Beispiel #1
0
 public function updateAlbum(Request $request)
 {
     $albums = json_decode($request->all()['albums'], true);
     $len = count($albums);
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     Album::truncate();
     Photo::truncate();
     Album::reindex();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     foreach ($albums as $a) {
         $album = new Album();
         $album->album_id = $a['id'];
         $album->name = $a['name'];
         $album->created_time = $a['created_time'];
         $album->save();
         $photos = $a['photos']['data'];
         foreach ($photos as $p) {
             $photo = new Photo();
             $photo->album_id = $album->id;
             $photo->photo_id = $p['id'];
             $photo->source = $p['source'];
             $photo->save();
         }
     }
     return '1';
 }
 public function doCreateAlbum(Guard $guard, Request $request)
 {
     if ($guard->guest()) {
         throw new AppException(AppException::NEED_SIGN_IN);
     }
     $musics = $request->get('musics');
     $coverImageId = $request->get('cover_image_id');
     $title = $request->get('title');
     $artist = $request->get('artist');
     $year = $request->get('year');
     $genre = $request->get('genre');
     $album = new Album();
     $album->title = $title;
     $album->artist = $artist;
     $album->year = $year;
     $album->genre = $genre;
     $album->coverImage()->associate($coverImageId);
     $album->user()->associate($guard->id());
     $album->save();
     foreach ($musics as $musicId) {
         /** @var Music $music */
         $music = Music::where('id', $musicId)->first();
         if (!$music) {
             continue;
         }
         $album->musics()->attach($musicId);
         if (!$music->coverImage) {
             $music->coverImage()->associate($album->coverImage);
             $music->save();
         }
     }
     return $this->buildResponse(trans('api.album.create.success'), Tools::toArray($album));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->name != "") {
         $album = new Album();
         $album->name = $request->name;
         $album->user_id = \Auth::user()->id;
         $album->save();
         return $album->id;
     }
 }
 /**
  * To create albums
  */
 public function store(Request $request)
 {
     $album = new Album();
     $album->title = $request->input('title');
     $album->publication = $request->input('publication');
     $album->save();
     $artists = $request->input('artists');
     foreach ($artists as $key => $value) {
         $album->artists()->create(['name' => $value['name'], 'rol' => $value['rol']]);
     }
     return ['created' => true];
 }
 public function saveAlbum(Request $request)
 {
     //Validating the album fields
     $validator = Validator::make($request->all(), ['album_name' => 'required|min:4', 'description' => 'required|min:30']);
     if ($validator->fails()) {
         return redirect('new-album')->withErrors($validator)->withInput();
     }
     //saving a new albums in database
     $Album = new Album();
     $Album->album_name = $request->input('album_name');
     $Album->description = $request->input('description');
     $Album->category_id = $request->input('cid');
     $Album->save();
     return redirect()->back();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $album = new Album();
     $album->fill($request->all());
     $image = $request->file('thumbnail');
     $fileName = "";
     if ($image->isValid()) {
         $path = public_path() . '/uploads/albums/';
         $fileName = str_random(32) . '.' . $image->getClientOriginalExtension();
         $image->move($path, $fileName);
     } else {
         App::abort(404);
     }
     $album->thumbnail = $fileName;
     $album->save();
     return Redirect::route('admin.album.show');
 }
 public function createAlbum($name, $description, $cover, $user_id)
 {
     try {
         if (!Storage::disk('local')->exists($user_id)) {
             Storage::makeDirectory($user_id);
         }
         $cover_name = str_slug($name) . str_random(10) . '.jpg';
         $cover_make = Image::make($cover);
         Storage::put($user_id . '/' . $cover_name, $cover_make->stream());
         $newAlbum = new Album();
         $newAlbum->name = $name;
         $newAlbum->desc = $description;
         $newAlbum->user_id = $user_id;
         $newAlbum->cover = $cover_name;
         $newAlbum->save();
         return array('status' => 1);
     } catch (Exception $exp) {
         return array('status' => 0);
     }
 }
Beispiel #8
0
 /**
  * 用于接收节目上传数据
  *
  * @param Request $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function programUpload(Request $request)
 {
     $album = new Album();
     $sheet = new Sheet();
     $resource = json_decode($request->get('musics'));
     for ($i = 0; $i < $request->get('num'); $i++) {
         /** @var Object $resObj */
         $resObj = $resource[$i];
         dump($sheet::where('song_name', 'ea')->first(['song_id', 'song_name', 'song_singer', 'name', 'user_id'])->toArray());
     }
     $album->album_name = $request->get('name');
     $album->album_author = $request->get('msg');
     $album->album_size = $request->get('allSize');
     $album->broadcast_at = $request->get('time');
     exit;
     $file = $request->file('pic');
     $filename = 'programmerPics/' . $album->album_name . '-' . $album->broadcast_at . '.' . $file->getExtension();
     if (!Storage::disk('local')->put($filename, file_get_contents($file->getRealPath()))) {
         return response()->json($file->getErrorMessage());
     }
     $album->album_cover = Storage::url($filename);
     $album->save();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\AddAlbumRequest $request)
 {
     //check album has artist
     $artist_id = (int) $request->get('artist_id');
     //dd($artist_id);
     $album_name = $request->get('name');
     //dd($album_name);
     $album = DB::select(DB::raw("select albums_has_artist.album_id as album_id,\n                                            albums_has_artist.artist_id as artist_id\n                                            from albums_has_artist\n                                            inner join albums on albums_has_artist.album_id = albums.id\n                                            \n                                            where albums_has_artist.artist_id = {$artist_id} and\n                                                  albums.name = '{$album_name}'"));
     /*$album = DB::table('albums_has_artist')
       ->join('albums', 'albums_has_artist.album_id', '=', 'albums.id')
       ->select('albums_has_artist.*')
       ->where('albums_has_artist.artist_id', '=', $request->get('artist_id'))
       ->where('albums.name', '=', $request->get('album_name'))
       ->first();    */
     //dd(!$album);
     if (!$album) {
         //bagong album
         $album = new Album(array('name' => $request->get('name'), 'recording_company' => $request->get('recording_company'), 'year_released' => $request->get('year_released')));
         $album->save();
         //may album na
         flash()->overlay('Album added!', 'Success!');
     }
     /*        if ( $request->get('artist_id')===NULL && 
                  $request->get('artist_name')===NULL && 
                  $request->get('album_name')===NULL && 
                  $request->get('track_id')==="" ) {
     
                 return view('album.create',
                             ['message'=>"Album Created", 
                              'artist_name' => NULL,
                              'artist_id' => NULL,
                              'track_id' => NULL,
                              'album_name' => NULL]);
             }
     */
     if ($request->get('artist_id')) {
         //existing artist, bagong album
         $albumsHasArtist = new AlbumsHasArtist(array('album_id' => $album->id, 'artist_id' => (int) $request->get('artist_id')));
         $albumsHasArtist->save();
     } else {
         //bagong artist, existing album
         $artist = DB::table('artists')->where('name', $request->get('artist_name'))->first();
         //dd($artist);
         if ($artist) {
             $albumsHasArtist = new AlbumsHasArtist(array('album_id' => $album->id, 'artist_id' => $artist->id));
             $albumsHasArtist->save();
         }
     }
     if ($request->get('track_id')) {
         //mag-on na si album at song
         $albumHasSong = new AlbumHasSong(array('album_id' => $album->id, 'track_id' => (int) $request->get('track_id')));
         $albumHasSong->save();
         //return redirect('track/create');
         return view('track.create');
         //,
         //             ['message'=>"Album Created"]);
     }
     return redirect('/album/create')->with(['track_id' => NULL, 'artist_id' => NULL, 'artist_name' => NULL, 'album_name' => NULL]);
     // return view('album.create',
     //             ['track_id' => NULL,
     //              'artist_id' => NULL,
     //              'artist_name' => NULL,
     //              'album_name' => NULL]);
 }