37 lines
969 B
PHP
37 lines
969 B
PHP
<?php
|
|
|
|
namespace App\Livewire\ShowPage\Tabs;
|
|
|
|
use App\Models\Person;
|
|
use App\Models\Show;
|
|
use Livewire\Component;
|
|
|
|
class Cast extends Component
|
|
{
|
|
public $show;
|
|
public $peopleByDepartment;
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.show-page.tabs.cast');
|
|
}
|
|
|
|
public function mount()
|
|
{
|
|
$this->show = Show::with('castList')->where('id', $this->show->id)->first();
|
|
|
|
$peopleByDepartment = [];
|
|
|
|
foreach ($this->show->castList as $castMember) {
|
|
if (!isset($peopleByDepartment[$castMember->pivot->known_for_department])) {
|
|
$peopleByDepartment[$castMember->pivot->known_for_department] = [];
|
|
}
|
|
$peopleByDepartment[$castMember->pivot->known_for_department][] = [
|
|
Person::find($castMember->pivot->person_id),
|
|
$castMember->pivot->character,
|
|
];
|
|
}
|
|
$this->peopleByDepartment = $peopleByDepartment;
|
|
}
|
|
}
|