cineflex/app/Http/Controllers/Managing/MovieController.php

70 lines
2.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers\Managing;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class MovieController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('atleast:employee');
2023-02-02 08:17:38 +01:00
$this->middleware('permission:READ_MOVIES')->only('index', 'show');
$this->middleware('permission:CREATE_MOVIES')->only('create', 'store');
$this->middleware('permission:UPDATE_MOVIES')->only('edit', 'update');
$this->middleware('permission:DELETE_MOVIES')->only('destroy');
}
2023-02-02 08:17:38 +01:00
public function index() {
return view('manage.movies.index', ['title' => "Manage Movies", 'movies' => \App\Models\Movie::all()]);
}
public function edit($id) {
$m = \App\Models\Movie::findOrfail($id);
return view('manage.movies.movie', ['title' => "Manage Movie", 'movie' => $m, 'showings' => $m->showings]);
}
public function createMovie() {
return view('manage.movies.create', ['title' => "Create Movie", 'genres' => \App\Models\Genre::all()]);
}
public function store() {
$movie = new \App\Models\Movie();
$movie->movie_name = request('movie_name');
$movie->movie_description = request('movie_description');
$movie->movie_year = request('movie_year');
$movie->movie_image = request('movie_image');
2023-02-02 08:17:38 +01:00
$movie->movie_length = request('movie_length');
$movie->movie_age_limit = request('movie_age_limit');
// $movie->user_id = auth()->user()->user_id;
$movie->genre_id = request('genre_id');
$movie->save();
return redirect()->route('manage.movies');
}
public function show($id) {
return view('main.movies.movie', ['title' => "Edit Movie", 'movie' => \App\Models\Movie::findOrfail($id)]);
}
public function update($id) {
$movie = \App\Models\Movie::findOrfail($id);
$movie->movie_name = request('movie_name');
$movie->movie_description = request('movie_description');
$movie->movie_year = request('movie_year');
$movie->movie_image = request('movie_image');
// $movie->user_id = auth()->user()->user_id;
$movie->genre_id = request('genre_id') !== null ? request('genre_id') : $movie->genre_id;
$movie->save();
return redirect()->route('manage.movies');
}
public function destroy($id) {
$movie = \App\Models\Movie::findOrfail($id);
$movie->delete();
return redirect()->route('manage.movies');
}
}