/** * TODO Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $album = Album::with('songs')->find($id); /** * * display album name */ echo '<strong>' . 'One to Many relationship' . '</strong>' . '<br>' . '<br>'; echo 'Album Name:' . '<li>' . $album->name; echo '<br>'; /** * Grab the songs for */ echo '<br>'; echo 'songs' . '<br>'; foreach ($album->songs as $key => $value) { /** * display songs for each album */ echo '<br>' . '<li>' . $value->name; } /** * Many to Many relationship * TODO Display album listeners */ echo '<br>'; echo '<br>'; echo '<br>'; echo '<strong>' . 'Many to Many relationship' . '</strong>' . '<br>'; echo '<br>' . 'Album listeners' . '<br>'; $album = Album::find($id); foreach ($album->listeners as $listeners) { echo '<li>' . $listeners->name; } }
public function getPhotos($album_id) { try { $photos = Album::find($album_id)->photos; return array('status' => 1, 'photos' => $photos, 'count' => $photos->count()); } catch (Exception $exp) { return array('status' => 0); } }
public function update(Request $request, $id) { $album = Album::findOrFail($id); if (Gate::denies('album_authorize', $album)) { return "authorize fails"; } $messages = ['title.required' => '标题不能为空', 'title.max' => '标题不能小于:max位', 'title.min' => '标题不能小于:min位']; $this->validate($request, ['title' => 'required|min:5|max:255'], $messages); $album = Album::find($id); $album->title = $request->title; $album->content = $request->content; $album->display_id = $request->display; $album->thumbnail = $request->thumbnail; $album->thumbnail2 = $request->thumbnail2; $album->free = $request->free; $album->published_at = $request->published_at; $album->save(); Session()->flash('status', 'Album update was successful!'); return redirect('/admin/albums/'); }
public function getForm($id) { $album = Album::find($id); return View::make('addimage')->with('album', $album); }
public function getDelete($id) { $album = Album::find($id); $album->delete(); return Redirect::route('index'); }
/** * album lead the pictures of this album * the album can be part of a model or a new album where $id = 'new' * * @param $model * @param $model_id * @param $id * * @return \Illuminate\Http\JsonResponse */ public function modelFilesGet($model, $model_id, $id) { //$this->_authorize($model, $model_id, $id); $this->album = Album::find($id); $file_names = $this->album->photos->pluck('location'); $folder = '/public/' . str_plural($model) . '/'; $files = []; foreach ($file_names as $file) { $files[] = ['name' => $file, 'size' => Storage::size($folder . $file), 'url' => '/img/cache/wm-rt-large/' . $file, 'deleteUrl' => route('image.delete', [$file]), 'deleteType' => 'GET']; } return response()->json(['files' => $files, 'album_id' => $this->album->id]); }
public function edit($id) { $album = Album::find($id); return view('pages.albums.edit', compact('album')); }
/** * To delete albums */ public function destroy($id) { $album = Album::find($id); foreach ($album->artists as $key => $value) { $value->delete(); } $album->delete(); return ['deleted' => true]; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($user, $id) { $album = Album::where(['id' => $id, 'user_id' => $user]); $is_del = true; if (count($album->get()->toArray())) { $images = Album::find($id); if (count($images) > 0) { $images = $images->images()->get()->toArray(); foreach ($images as $image) { $comment_img = Comment_image::where('image_id', $image['id']); if (count($comment_img->get()->toArray())) { if (false == $comment_img->delete()) { $is_del = false; } } if (false == unlink(public_path() . '/' . $image['fullsize_url']) || false == Image::destroy($image['id'])) { $is_del = false; break; } } } $album_id = $album->get()->first()->id; $comment = Comment_album::where('album_id', $album_id); if (count($comment->get()->toArray())) { if (false == $comment->delete()) { $is_del = false; } } if ($album->delete() && true == $is_del) { return redirect()->route('album.index', $user)->with(['message' => 'Album has been delete.']); } } return redirect()->route('album.index', $user)->withErrors('Can not delete album.'); }
public function getPhotos($album_id) { $album_name = Album::find($album_id)->name; return view('dashboard.album', ['album_id' => $album_id, 'name' => $album_name]); }
public function getForm($id) { $album = Album::find($id); return view('admin.imagegallery.addimage')->with('album', $album); }