/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $listId) { $list = $this->list->find($listId); if (Gate::denies('manage-todo', $list)) { abort(403, 'You dont have permissions to do that!!'); } $todo = $list->todos()->create($request->only('name', 'user_id', 'deadline')); return $todo->with('responsible')->find($todo->id); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('lists')->delete(); DB::table('todos')->delete(); $burimi = User::find(1); $kiqa = User::find(2); $drila = User::find(3); //new list $list = ListModel::create(['name' => 'Shopping List']); $list->collaborators()->attach($burimi); $list->collaborators()->attach($kiqa); $list->collaborators()->attach($drila); //new list $list = ListModel::create(['name' => 'Lessons']); //new list $list->collaborators()->attach($burimi); $list->collaborators()->attach($kiqa); $list->todos()->create(['name' => 'Upgrade server']); $list->todos()->create(['name' => 'Install patches', 'user_id' => $kiqa->id, 'deadline' => Carbon::now()]); $list->todos()->create(['name' => 'Remove old data', 'finished' => 1]); ListModel::create(['name' => 'Mix']); Model::reguard(); }
/** * @return static */ private function getAllLists() { return $this->list->where('archived', '!', 'archived'); }