Esempio n. 1
0
 public function actionDelete($id)
 {
     $user = Auth::user();
     $genre = Genre::where('user_id', '=', $user->id)->findOrFail($id);
     $genre->delete($genre);
     \Session::flash('flash_message', 'You have successfully deleted a genre.');
     return redirect('genres');
 }
Esempio n. 2
0
 public function getBook()
 {
     $books = Book::join('genre', 'genre.id', '=', 'book.genre_id')->join('author', 'author.id', '=', 'book.author_id')->join('publisher', 'publisher.id', '=', 'book.publisher_id')->select('book.id', 'title', 'genre_id', 'genre.name as genre_name', 'author_id', 'author.name as author_name', 'publisher_id', 'publisher.name as publisher_name', 'image', 'isbn', 'description_short', 'price', 'sale', 'quantity')->where('book.deleted', '=', 0)->get();
     $genres = Genre::where('deleted', '=', 0)->orderBy('name')->get();
     $authors = Author::where('deleted', '=', 0)->orderBy('name')->get();
     $publishers = Publisher::where('deleted', '=', 0)->orderBy('name')->get();
     $data = array('books' => $books, 'authors' => $authors, 'genres' => $genres, 'publishers' => $publishers);
     return view('admin.pages.book')->with('data', $data);
 }
Esempio n. 3
0
 public function viewUpdate($id)
 {
     $user = Auth::user();
     $movie = Movie::where('user_id', '=', $user->id)->findOrFail($id);
     $genres = Genre::where('user_id', '=', $user->id)->orderBy('name', 'asc')->get();
     $ratings = Rating::where('user_id', '=', $user->id)->orderBy('name', 'asc')->get();
     $directors = Director::where('user_id', '=', $user->id)->orderBy('name', 'asc')->get();
     $writers = Writer::where('user_id', '=', $user->id)->orderBy('name', 'asc')->get();
     $casts = Cast::where('user_id', '=', $user->id)->orderBy('name', 'asc')->get();
     $labels = Label::where('user_id', '=', $user->id)->orderBy('name', 'asc')->get();
     return view('movies.viewUpdate')->with('movie', $movie)->with('genres', $genres)->with('ratings', $ratings)->with('directors', $directors)->with('writers', $writers)->with('casts', $casts)->with('labels', $labels);
 }
Esempio n. 4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $url = "http://omdbapi.com/?i=";
     // get all the videos with an IMDB ID
     $videos = Video::whereNotNull('imdb')->get();
     echo "\nUpdating....\n\n";
     // loop through all the videos
     foreach ($videos as $video) {
         // get JSON data
         $json = file_get_contents($url . $video->imdb);
         $obj = json_decode($json);
         // update fields of the video with JSON data
         $video->product->name = $obj->Title;
         $video->poster = '/img/posters/' . $video->imdb . '.jpg';
         $video->release_year = $obj->Year;
         if ($obj->Released !== 'N/A') {
             $video->release_date = new \DateTime($obj->Released);
         }
         // download the poster
         if (!file_exists('/img/posters/' . $video->imdb . '.jpg') && filter_var($obj->Poster, FILTER_VALIDATE_URL) !== false) {
             $buffer = file_get_contents($obj->Poster);
             $file = fopen(public_path() . '/img/posters/' . $video->imdb . '.jpg', 'w+');
             fwrite($file, $buffer);
             fclose($file);
         }
         // save the video
         $video->save();
         // delete the products gnere
         DB::table('genre_product')->where('product_id', $video->product_id)->delete();
         // get the genres
         $genres = explode(',', $obj->Genre);
         foreach ($genres as $key => $genre) {
             $genres[$key] = trim($genre);
         }
         // add the genres
         foreach ($genres as $genre) {
             // if genre does not exist create it
             $record = Genre::where('name', $genre)->first();
             if ($record === null) {
                 $record = Genre::create(['name' => $genre]);
             }
             // attatch genre to video
             $video->product->genres()->attach([$record->id]);
         }
         // log to screen
         echo $video->product_id . ". \t" . $video->product->name . " updated successfully.\n";
     }
 }
Esempio n. 5
0
 public function StoreGame(Request $request, $info)
 {
     // get the genres
     $genres = str_getcsv($request->genre);
     foreach ($genres as $key => $genre) {
         $genres[$key] = trim($genre);
     }
     // create product record
     $product = new Product($request->all());
     // use database transaction to save the records
     DB::transaction(function () use($product, $info, $genres) {
         // save the product record
         $product->save();
         // set the product id of the details record
         $info->product_id = $product->id;
         if (filter_var($info->poster, FILTER_VALIDATE_URL) !== false) {
             // download the poster
             if (!file_exists('/img/games/' . $info->product_id . '.jpg')) {
                 $buffer = file_get_contents($info->poster);
                 $file = fopen(public_path() . '/img/games/' . $info->product_id . '.jpg', 'w');
                 fwrite($file, $buffer);
                 fclose($file);
             }
             // set the poster url
             $info->poster = '/img/games/' . $info->product_id . '.jpg';
         }
         // save the details record
         $info->save();
         // add the genres
         foreach ($genres as $genre) {
             // if genre does not exist create it
             $record = Genre::where('name', $genre)->first();
             if ($record === null) {
                 $record = Genre::create(['name' => $genre]);
                 $product->genres()->attach([$record->id]);
             } else {
                 $product->genres()->attach([$record->id]);
             }
         }
     });
 }
Esempio n. 6
0
 public function getGenre()
 {
     $genres = Genre::where('deleted', '=', 0)->orderBy('name')->get();
     return view('admin.pages.genre')->with('genres', $genres);
 }