И одна сводная таблица Video_Category, потому что в категории может быть больше видео.
Я пытался получить все идентификаторы из сводной таблицы:< /p>
Код: Выделить всё
$allcategoryvideos = CategoryVideo::where('category_id', $category_id)->pluck('video_id');
Код: Выделить всё
$featured = [];
foreach ($allcategoryvideos as $video){
array_push($featured, [
$video = Video::where('id', $video)->whereNotNull('featured')->first(),
]);
}
return $featured;
Код: Выделить всё
public function videofeatured() {
return $this->hasOne(Video::class, 'id', 'video_id')->where('featured', 1);
}
Код: Выделить всё
[[{"id":1,"created_at":"2022-07-24T14:20:30.000000Z","updated_at":"2022-07-24T14:20:34.000000Z","name":"Video 1","slug":"video","description":"123","video_link":"123","mp3_link":"123","image_url":"123","minutes":10,"sort_id":null,"featured":1,"is_visible":1}],[null]]
Большое спасибо за помощь.
Подробнее здесь: https://stackoverflow.com/questions/730 ... -condition