/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $project = \App\Project::findOrFail($id); $yearslist = \App\Year::lists('year', 'id'); $companies = \App\Company::findOrFail($project->company_id); $officers_for_dropdown = \App\Officer::lists('last_name', 'id'); return view('pages.project.edit', compact('project', 'companies', 'officers_for_dropdown', 'yearslist')); }
/** * Run the database seeds. * * @return void */ public function run() { # First, create an array of all the projects we want to associate years with $projects = [1 => [1, 2, 3, 4, 5], 2 => [1, 2, 3, 4, 5], 3 => [1, 2, 5, 7, 8], 4 => [1, 2, 3, 4, 5, 6, 7, 8]]; # Now loop through the above array, creating a new pivot for each book to tag foreach ($projects as $projectid => $years) { # First get the project $project = \App\Project::where('id', 'like', $projectid)->first(); # Now loop through each year for this project, adding the pivot foreach ($years as $yearid) { $year = \App\Year::where('id', 'LIKE', $yearid)->first(); # Connect this tag to this book $project->years()->save($year); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function ConfirmDelete($id) { # Get the Project to be deleted $year = \App\Year::findOrFail($id); return view('pages.year.delete', compact('year')); }