Example #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     if (Gate::denies('admin')) {
         abort(403);
     }
     // TODO "Add Image" button
     $out = ['form_route' => ['route' => ['image.update', $id], 'method' => 'PUT', 'class' => 'form-horizontal', 'files' => true]];
     if (count(Request::old())) {
         $rq = Request::old();
         $out['image'] = new Image($rq);
         if (isset($rq['artist_id']) && is_array($rq['artist_id'])) {
             $out['image']->artists = Artist::whereIn('id', $rq['artist_id'])->get();
         }
         if (isset($rq['release_id']) && is_array($rq['release_id'])) {
             $out['image']->releases = Release::whereIn('id', $rq['release_id'])->get();
         }
         if (isset($rq['track_id']) && is_array($rq['track_id'])) {
             $out['image']->tracks = Track::whereIn('id', $rq['track_id'])->get();
         }
     } else {
         $out['image'] = Image::findOrNew($id);
     }
     return view('images.form', $out);
 }