/** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { if ($this->djs == null) { $this->djs = DJ::orderBy('name', 'asc')->get(); } $view->with('djs', $this->djs); }
/** * Reverse the migrations. * * @return void */ public function down() { Schema::table('user', function (Blueprint $table) { $table->string('dj_name')->nullable(); $table->string('picture')->default('default.jpg'); $table->boolean('active')->default(false); }); $djs = DJ::all(); foreach ($djs as $dj) { $user = User::find($dj->id); if ($user != null) { $user->fill(['dj_name' => $dj->name, 'picture' => $dj->picture, 'active' => true]); $user->save(); } } Schema::drop('djs'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function delete($id) { $timeslots = TimeSlot::where('dj', $id)->count(); if ($timeslots > 0) { return redirect()->back()->with('error', 'Remove DJ from schedule before deleting.'); } $dj = DJ::findOrFail($id); File::delete(public_path() . '/img/djs/' . $dj->picture); DJ::destroy($id); return redirect()->route('admin.djs.index')->with('success', 'DJ Deleted!'); }