forked from aslan/applicant-site
39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?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);
|
|
}
|
|
}
|