2025-01-26 21:36:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2025-02-16 21:11:07 +02:00
|
|
|
use App\Http\Requests\Movie\CommentRequest;
|
2025-01-29 22:33:09 +02:00
|
|
|
use App\Models\Comment;
|
2025-10-09 00:22:54 +03:00
|
|
|
use App\Models\MediaList;
|
2025-01-26 21:36:05 +02:00
|
|
|
use App\Models\Movie;
|
|
|
|
|
use Illuminate\Http\Request;
|
2025-10-09 00:22:54 +03:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2025-01-26 21:36:05 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2025-08-11 21:40:50 +03:00
|
|
|
$comments = Comment::where('entity_id', $movie->id)
|
|
|
|
|
->where('entity_type', Comment::TYPE_MOVIE)
|
2025-01-29 22:33:09 +02:00
|
|
|
->paginate(15);
|
|
|
|
|
|
2025-10-09 00:22:54 +03:00
|
|
|
$userLists = [];
|
|
|
|
|
if (Auth::check()) {
|
|
|
|
|
$userLists = MediaList::whereNotIn('name', MediaList::SPECIAL_LISTS)
|
|
|
|
|
->where('user_id', Auth::user()->id)
|
|
|
|
|
->get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return view('movie.show', compact('movie', 'comments', 'userLists'));
|
2025-01-26 21:36:05 +02:00
|
|
|
}
|
2025-02-16 21:11:07 +02:00
|
|
|
|
|
|
|
|
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!');
|
|
|
|
|
}
|
2025-01-26 21:36:05 +02:00
|
|
|
}
|