67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
<?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');
|
|
}
|
|
|
|
public function showAllMovies() {
|
|
// has permission READ_MOVIES ?
|
|
if(!Auth::user()->allowedTo('READ_MOVIES')) {
|
|
abort(403);
|
|
}
|
|
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');
|
|
// $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');
|
|
}
|
|
|
|
}
|