/
home
/
maktab
/
server
/
app
/
Http
/
Controllers
/
api
/
File Upload :
llllll
Current File: /home/maktab/server/app/Http/Controllers/api/CloonyController.php
<?php namespace App\Http\Controllers\api; use App\Http\Controllers\Controller; use App\Models\Cloony; use App\Models\Maktab; use App\Models\User; use App\Models\Users_to_maktab; use Illuminate\Http\Request; class CloonyController extends Controller { public function listMaktab($cloony_id) { $maktab = Maktab::with('master')->where('cloony_id', $cloony_id) ->where('active', true) ->get(); return response()->json($maktab); } public function listMasterMaktab($maktab_id) { $users = User::with([ 'file', 'maktab', 'type_cnt', 'users_to_maktab' => function ($query) use ($maktab_id) { $query->where('maktab_id', $maktab_id); }, 'users_to_maktab.type_cnt' ])->where(function ($query) use ($maktab_id) { $query->where('maktab_id', $maktab_id) ->whereIn('type', [4, 6]) ->where('active', true); })->orWhereHas('users_to_maktab', function ($query) use ($maktab_id) { $query->where('maktab_id', $maktab_id); }) ->get(); $finalUsers = collect(); foreach ($users as &$user) { if ($user->users_to_maktab && $user->users_to_maktab->isNotEmpty()) { foreach ($user->users_to_maktab as $userToMaktab) { unset($user->type_cnt); $user->type_cnt = $userToMaktab->type_cnt; $finalUsers->push(clone $user); } } else { $finalUsers->push($user); } } return $finalUsers; } public function listCloony() { $cloony = Cloony::with('master')->get(); return response()->json($cloony); } }
Copyright ©2k19 -
Hexid
|
Tex7ure