/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $rooms = Room::with(["building" => function ($query) { $query->select('name', 'id', 'building_sn'); }])->get(); $today = new \DateTime('today'); foreach ($rooms as &$room) { $contract = Contract::where('room_id', $room['id'])->where('end_time', '>=', $today)->get(); if ($contract->count() > 0) { $room['hasContract'] = 1; $room['contract'] = $contract[0]; } else { $room['hasContract'] = 0; } } return $rooms; }
use App\Http\Controllers\RoomsController; use App\Http\Controllers\TimeslotsController; use App\Room; use App\Timeslot; Route::model('room', 'App\\Room'); Route::get('/', function () { return view('welcome'); }); Route::get('/home', HomeController::class . '@index'); Route::get('/week', function () { return View::make('control-pages.week', ['rooms' => Room::all()]); }); Route::resource('room', RoomsController::class); Route::resource('timeslot', TimeslotsController::class); Route::get('/api/week', function () { return ['Maandag' => Timeslot::where('day_id', '1')->orderBy('begin')->get(), 'Dinsdag' => Timeslot::where('day_id', '2')->orderBy('begin')->get(), 'Woensdag' => Timeslot::where('day_id', '3')->orderBy('begin')->get(), 'Donderdag' => Timeslot::where('day_id', '4')->orderBy('begin')->get(), 'Vrijdag' => Timeslot::where('day_id', '5')->orderBy('begin')->get(), 'Zaterdag' => Timeslot::where('day_id', '6')->orderBy('begin')->get(), 'Zondag' => Timeslot::where('day_id', '7')->orderBy('begin')->get()]; }); Route::get('/api/week/{room}', function (Room $room) { $days_list = \App\Day::all(); $days = []; foreach ($days_list as $day) { $days[$day->day] = []; } foreach ($room->timeslots as $timeslot) { $days[$timeslot->day->day][] = $timeslot; } return $days; }); Route::get('/api/rooms', function () { return \App\Room::with('timeslots')->get(); });
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return Room::with("building", "contract", "feeplans")->has('contract')->get(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return Room::with("building", "contract", "feeplans")->has('contract')->whereHas('feeplans', function ($query) { $query->where('status', 0); })->get(); }