/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, Piece $piece)
 {
     $data = $request->except(['file', 'delete_image']);
     if ($request->input('delete_image')) {
         $this->deleteImage($piece->imagePath);
         $piece->image = '';
         $piece->save();
     }
     if ($request->hasFile('file')) {
         $piece->image = $this->saveImage($request);
     }
     $piece->update($data);
     return redirect()->action('Admin\\PiecesController@index');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     foreach (Piece::all() as $piece) {
         $medium = Medium::find(rand(1, Medium::count() - 1));
         $piece->media()->attach($medium);
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(Studio $studio, Event $event)
 {
     $artists = Artist::all()->lists('name', 'id');
     $pieces = Piece::lists('title', 'id')->all();
     $event->date = $event->starts->format('Y-m-d');
     $event->startTimeField = $event->starts->format('H:i');
     $event->endTimeField = $event->ends->format('H:i');
     return view('admin.studio.events.edit', compact('studio', 'event', 'artists', 'pieces'));
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     $router->model('studios', 'App\\Studio');
     $router->model('events', 'App\\Event');
     $router->model('pieces', 'App\\Piece');
     $router->model('categories', 'App\\Category');
     $router->model('orders', 'App\\Order');
     $router->model('parties', 'App\\PartyRequest');
     $router->bind('studioSlug', function ($value) {
         return \App\Studio::where('slug', $value)->first();
     });
     $router->bind('pieceSlug', function ($value) {
         return \App\Piece::where('slug', $value)->first();
     });
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     return view('pieces.index', ['pieces' => Piece::paginate(12)]);
 }
 public function getIndex()
 {
     $pieces = Piece::orderBy('title', 'asc')->paginate(20);
     return view('gallery.index', compact('pieces'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(Studio $studio, Event $event)
 {
     $pieces = Piece::lists('title', 'id');
     $categories = Category::lists('name', 'id');
     return view('admin.studios.events.edit', compact('studio', 'event', 'pieces', 'categories'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(Image $image)
 {
     $pieces = Piece::lists('title', 'id')->all();
     $artists = Artist::all()->lists('name', 'id');
     return view('admin.images.edit', compact('image', 'pieces', 'artists'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Piece $piece)
 {
     if ($piece->events()->future()->count()) {
         return redirect()->route('admin.pieces.show', $piece)->with('messageError', 'This Piece is used in upcoming events and cannont be deleted.');
     }
     $piece->delete();
     return redirect()->route('admin.pieces.index')->with('messageError', 'Piece deleted');
 }