47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\Movie\CommentRequest;
|
|
use App\Models\Comment;
|
|
use App\Models\Movie;
|
|
use Illuminate\Http\Request;
|
|
|
|
class MovieController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$movies = Movie::orderBy('release_date', 'ASC')->paginate(60);
|
|
|
|
return view('movie.index', compact('movies'));
|
|
}
|
|
|
|
public function show(string $slug)
|
|
{
|
|
$movie = Movie::with('director', 'watchProviders')
|
|
->where('slug', $slug)
|
|
->firstOrFail();
|
|
|
|
$comments = Comment::where('entity_id', $movie->id)
|
|
->where('entity_type', Comment::TYPE_MOVIE)
|
|
->paginate(15);
|
|
|
|
return view('movie.show', compact('movie', 'comments'));
|
|
}
|
|
|
|
public function storeComment(CommentRequest $request, string $movieSlug)
|
|
{
|
|
$movie = Movie::where('slug', $movieSlug)->firstOrFail();
|
|
|
|
Comment::create([
|
|
'entity_id' => $movie->id,
|
|
'entity_type' => Comment::TYPE_MOVIE,
|
|
'user_id' => auth()->user()->id,
|
|
'content' => $request->get('content'),
|
|
'published_at' => new \DateTime(),
|
|
]);
|
|
|
|
return redirect()->back()->with('success', 'Comment posted!');
|
|
}
|
|
}
|