prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
2 changed files with 40 additions and 1 deletions
Showing only changes of commit 19b075c755 - Show all commits

View File

@ -0,0 +1,38 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Direction;
use App\Models\EntranceExamination;
use Illuminate\Http\Request;
use function _PHPStan_cc8d35ffb\React\Promise\map;
class CalculatorController extends Controller
{
public function findDirectionFromSubjects(Request $request)
{
$getsSubjects = $request->input();
$countUserSubjects = count($getsSubjects);
// $entranceExamination = EntranceExamination::all()
// ->whereIn('subject_id', $result)
// ->where('subject_type_id','=',1)
// ->select('subject_id','direction_id')
// ->whereIn('subject_id', $result)
// ->groupBy('direction_id')
// ->toArray();
// dd($entranceExamination);
// $directions = Direction::all();
$findIds = EntranceExamination::all()
->select("direction_id", "subject_id")
->groupBy('direction_id')
->map(function ($direction) {
return $direction->map(fn($item) => $item['subject_id']);
})
->filter(fn ($direction) => count($direction) <= $countUserSubjects)
->keys();
$directions = Direction::whereIn('id', $findIds)->get();
return response()->json($directions);
}
}

View File

@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\admin\PageController;
use App\Http\Controllers\Api\CalculatorController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
@ -19,4 +20,4 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('/calc', [PageController::class, 'calculator'])->name('calculator');
Route::post('/calculator', [CalculatorController::class, 'findDirectionFromSubjects'])->name('calculator');