/** * Bootstrap any application services. * * @return void */ public function boot() { Drive::creating(function ($drive) { // Make sure the user is logged in if (!Auth::check()) { return false; } // Check that the vehicle belongs to the learner if ($drive->getAttribute('vehicle_id')) { return $this->ownsVehicle($drive); } return true; }); }
/** * Sync the relations of a given drive * (e.g. road types, traffic conditions, etc.) * * @param Drive $d * @param DriveRequest $request */ private function syncDriveRelations(Drive $d, DriveRequest $request) { if ($request->has('tasks_list')) { $d->tasks()->sync($request->input('tasks_list')); } if ($request->has('road_types_list')) { $d->road_types()->sync($request->input('road_types_list')); } if ($request->has('road_conditions_list')) { $d->road_conditions()->sync($request->input('road_conditions_list')); } if ($request->has('traffic_conditions_list')) { $d->traffic_conditions()->sync($request->input('traffic_conditions_list')); } if ($request->has('visibilities_list')) { $d->visibilities()->sync($request->input('visibilities_list')); } }