Example #1
0
 public function storeDvd()
 {
     $input = $this->request->request->all();
     // Validate the data
     if (($validator = Dvd::validate($input)) !== true) {
         session()->addErrors($validator);
         session()->flashInput($input);
         return redirect(l('admin/dvd/add'));
     }
     // Validate the image
     if (($imageValidator = Dvd::validateImage()) !== true) {
         session()->addErrors($imageValidator);
         session()->flashInput($input);
         return redirect(l('admin/dvd/add'));
     }
     // Save file with random name
     $image = $_FILES['image'];
     $name = $image['type'] == 'image/jpeg' ? uniqid('dvd_') . '.jpg' : uniqid('dvd_') . '.png';
     if (!move_uploaded_file($_FILES['image']['tmp_name'], PUBLIC_PATH . 'uploads/' . $name)) {
         session()->addErrors(new Message(['Image was not uploaded - please try again']));
         session()->flashInput($input);
         return redirect(l('admin/dvd/add'));
     }
     // Insert into database
     $dvd = new Dvd();
     $dvd->create(['title' => $input['title'], 'genre_id' => $input['genre'], 'price_band' => $input['price'], 'year' => $input['year'], 'synopsis' => $input['synopsis'], 'director' => $input['director'], 'cast' => $input['cast'], 'image' => $name]);
     session()->addSuccess('Dvd successfully added');
     return redirect(l('admin/dvds'));
 }
 public function store(Request $request)
 {
     $validation = Validator::make($request->all(), ['dvd' => 'required', 'genre' => 'required', 'rating' => 'required', 'label' => 'required', 'sound' => 'required', 'format' => 'required']);
     if ($validation->fails()) {
         return redirect('dvds/create')->withInput()->withErrors($validation);
     }
     $dvd = new Dvd(['title' => $request->input('dvd'), 'genre_id' => $request->input('genre'), 'rating_id' => $request->input('rating'), 'label_id' => $request->input('label'), 'sound_id' => $request->input('sound'), 'format_id' => $request->input('format')]);
     $dvd->save();
     return redirect('dvds/create')->with('success', true);
 }
 public function store(Request $request)
 {
     $validation = Validator::make($request->all(), ['title' => 'required|unique:dvds,title']);
     if ($validation->passes()) {
         $dvd = new Dvd();
         $dvd->title = $request->input('title');
         $dvd->save();
         return ['dvd' => $dvd];
     }
     return Response::json(['errors' => ['title' => $validation->errors()->get('title')]], 422);
 }
 public function store(Request $request)
 {
     $validation = Validator::make($request->all(), ['title' => 'required|unique:dvds', 'award' => 'required', 'genre_id' => 'required|integer|exists:genres,id', 'rating_id' => 'required|integer|exists:ratings,id']);
     if ($validation->passes()) {
         $dvd = new Dvd();
         $dvd->title = $request->input('title');
         $dvd->award = $request->input('award');
         $dvd->genre_id = $request->input('genre_id');
         $dvd->rating_id = $request->input('rating_id');
         $dvd->save();
         return ['dvd' => $dvd];
     }
     return Response::json(['errors' => ['title' => $validation->errors()->get('title'), 'award' => $validation->errors()->get('award'), 'genre_id' => $validation->errors()->get('genre_id'), 'rating_id' => $validation->errors()->get('rating_id')]], 422);
 }
 public function store(Request $request)
 {
     $validation = Validator::make($request->all(), ['title' => 'required']);
     if ($validation->fails()) {
         return redirect('dvds/create')->withInput()->withErrors($validation);
     }
     $dvd = new Dvd();
     $dvd->title = $request->input('title');
     $dvd->format_id = $request->input('format');
     $dvd->label_id = $request->input('label');
     $dvd->sound_id = $request->input('sound');
     $dvd->genre_id = $request->input('genre');
     $dvd->rating_id = $request->input('rating');
     $dvd->save();
     return redirect('dvds/create')->withFlashMessage('DVD Was Added Successfully.');
 }
 public function showSingleDvd($id)
 {
     $dvd = Dvd::find($id);
     if (!$dvd) {
         return Response::json(['error' => 'DVD not found'], 404);
     }
     $genres = Dvd::find($id)->genre;
     $ratings = Dvd::find($id)->rating;
     return ['dvd' => $dvd, 'genres' => [$genres], 'ratings' => [$ratings]];
 }
Example #7
0
 public function genres($id)
 {
     $genre = Genre::find($id);
     $dvds = Dvd::with('genre', 'rating', 'label')->where('genre_id', '=', "{$id}")->get();
     return view('genre', ['dvds' => $dvds, 'genre' => $genre]);
 }
 public function show($id)
 {
     $genre = Genre::find($id);
     $dvds = Dvd::with('rating', 'genre', 'label')->where('genre_id', '=', $id)->get();
     return view('genre', ['genre' => $genre, 'dvds' => $dvds]);
 }
 public function insert_dvd(Request $request)
 {
     $validation = Validator::make($request->all(), ['title' => 'required|min:3', 'label' => 'required', 'sound' => 'required', 'genre' => 'required', 'rating' => 'required|numeric|min:1|max:10', 'format' => 'required']);
     if ($validation->fails()) {
         return redirect("dvds/create")->withInput()->withErrors($validation);
     }
     $dvd = Dvd::create(['title' => $request->input('title'), 'label_id' => $request->input('label'), 'sound_id' => $request->input('sound'), 'genre_id' => $request->input('genre'), 'rating_id' => $request->input('rating'), 'format_id' => $request->input('format')]);
     if (!is_null($dvd)) {
         return redirect("dvds/create")->with('success', true);
     }
 }
 public function display_dvds_by_genre($genre_id)
 {
     $dvds = Dvd::with('genre', 'rating', 'label')->where('genre_id', '=', $genre_id)->get();
     $genre = Genre::find($genre_id);
     return view("dvds_by_genre", ['dvds' => $dvds, 'genre' => $genre]);
 }