forked from aslan/applicant-site
prodV1 #2
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\admin\PageController;
|
use App\Http\Controllers\admin\PageController;
|
||||||
|
use App\Http\Controllers\Api\CalculatorController;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
@ -19,4 +20,4 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
||||||
return $request->user();
|
return $request->user();
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::post('/calc', [PageController::class, 'calculator'])->name('calculator');
|
Route::post('/calculator', [CalculatorController::class, 'findDirectionFromSubjects'])->name('calculator');
|
||||||
|
|
Loading…
Reference in New Issue