some progress
This commit is contained in:
@@ -32,6 +32,5 @@ class Cast extends Component
|
||||
];
|
||||
}
|
||||
$this->peopleByDepartment = $peopleByDepartment;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,36 @@
|
||||
|
||||
namespace App\Livewire\MoviePage\Tabs;
|
||||
|
||||
use App\Models\Movie;
|
||||
use App\Models\Person;
|
||||
use Livewire\Component;
|
||||
|
||||
class Crew extends Component
|
||||
{
|
||||
public $movie;
|
||||
public $peopleByDepartment;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.movie-page.tabs.crew');
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->movie = Movie::with('crewList')->where('id', $this->movie->id)->first();
|
||||
|
||||
$peopleByDepartment = [];
|
||||
|
||||
foreach ($this->movie->crewList as $castMember) {
|
||||
|
||||
if (!isset($peopleByDepartment[$castMember->pivot->department])) {
|
||||
$peopleByDepartment[$castMember->pivot->department] = [];
|
||||
}
|
||||
$peopleByDepartment[$castMember->pivot->department][] = [
|
||||
Person::find($castMember->pivot->person_id),
|
||||
$castMember->pivot->job,
|
||||
];
|
||||
}
|
||||
$this->peopleByDepartment = $peopleByDepartment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class Movie extends Model
|
||||
|
||||
public function crewList()
|
||||
{
|
||||
return $this->belongsToMany(Person::class, 'movie_crew', 'movie_id', 'person_id');
|
||||
return $this->belongsToMany(Person::class, 'movie_crew', 'movie_id', 'person_id')->withPivot('department', 'job');
|
||||
}
|
||||
|
||||
public function images()
|
||||
|
||||
Reference in New Issue
Block a user