Files
movies/app/Http/Controllers/CelebrityController.php
T
2025-02-10 01:58:12 +02:00

51 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Person;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CelebrityController extends Controller
{
public function index()
{
$celebrities = Person::paginate(25);
return view('celebrity.index', compact('celebrities'));
}
public function show(string $slug)
{
$celebrity = Person::where('slug', $slug)->first();
// movies by job
$movies = DB::table('movies')
->leftJoin('movie_cast', 'movie_cast.movie_id', '=', 'movies.id')
->where('movie_cast.person_id', '=', $celebrity->id)
->get();
// movies crew
$moviesByDepartments = [];
foreach ($movies as $movie) {
$moviesByDepartments[$movie->known_for_department][]= $movie;
}
$showsByDepartment = [];
$shows = DB::table('shows')
->leftJoin('show_cast', 'show_cast.show_id', '=', 'shows.id')
->where('show_cast.person_id', '=', $celebrity->id)
->get();
foreach ($shows as $show) {
$showsByDepartment[$show->known_for_department][]= $show;
}
return view('celebrity.show', compact('celebrity', 'moviesByDepartments', 'showsByDepartment'));
}
}