我得到这个Undefined property: stdClass::$plot error
注意:dd($video,$VodDetail,$tmdb );
已全部设置,并具有必需的详细信息。
$article= new Article();
$article->type = 'link';
$article->title = $video->name;
$article->description = ($VodDetail->plot)?$VodDetail->plot:($tmdb->overview)?$tmdb->overview:'';
$article->releaseDate = ($VodDetail->releasedate)?Carbon::parse($VodDetail->releasedate)->format('Y'):($tmdb->release_date)?Carbon::parse($tmdb->release_date)->format('Y'):'';
$article->stream_id = $video->stream_id;
$article->trailer = ($VodDetail->youtube_trailer)?'https://www.youtube.com/embed/'.$VodDetail->youtube_trailer:null;
$article->rating = ($video->rating)?$video->rating:($tmdb->vote_average)?$tmdb->vote_average:'';
$article->director = ($VodDetail->director)?$VodDetail->director:null;
$article->runtime = ($VodDetail->duration)?$VodDetail->duration:null;
$article->avatar = ($img_path) ? url(url($img_path)) : 'default.jpg';
$article->background_image = ($VodDetail->backdrop_path) ? (($VodDetail->backdrop_path[0])?$VodDetail->backdrop_path[0]:null) : null;
$article->genre = ($VodDetail->genre) ? preg_replace("' / '", ",", $VodDetail->genre) : null;
$article->category_idFk = Category::where('title', 'LIKE', $xtreamCategories[$video->category_id])->first()->category_id ?: null;
$article->tmdb_id = ($VodDetail->tmdb_id)?$VodDetail->tmdb_id:($tmdb->id)?$tmdb->id:'';
$article->created_at = Carbon::now()->toDateTimeString();
$article->updated_at = Carbon::now()->toDateTimeString();
$article->imdb_id = ($tmdb->imdb_id)?$tmdb->imdb_id:null;
$article->secondary_title = ($tmdb->original_title)?$tmdb->original_title:null;
$article->language_name = ($tmdb->spoken_languages)?$tmdb->spoken_languages[0]->name:null;
$article->save();
如果我将dd($article);
放在$article-save();
之前,则会得到以下结果:
Article {#4048
#primaryKey: "article_id"
#table: "articles"
+timestamps: false
#fillable: array:15 [
0 => "subtitle_path"
1 => "stream_id"
2 => "type"
3 => "imdb_id"
4 => "runtime"
5 => "title"
6 => "releaseDate"
7 => "description"
8 => "avatar"
9 => "rating"
10 => "category_idFk"
11 => "director"
12 => "genre"
13 => "created_at"
14 => "updated_at"
]
#attributes: array:19 [
"type" => "link"
"title" => "Sacudete Las Penas"
"description" => "One of the prisoners who have to spend a long season in jail, González, ...."
"releaseDate" => "2018"
"stream_id" => 9415
"trailer" => "https://www.youtube.com/embed/5jstm_JeyW8"
"rating" => 10.0
"director" => null
"runtime" => "01:25:17"
"avatar" => "default.jpg"
"background_image" => null
"genre" => "Drama"
"category_idFk" => 1
"tmdb_id" => 518326
"created_at" => "2018-08-30 07:30:45"
"updated_at" => "2018-08-30 07:30:45"
"imdb_id" => "tt7945596"
"secondary_title" => "Sacudete Las Penas"
"language_name" => "Español"
]
#guarded: array:1 [
0 => "*"
]
}
答案 0 :(得分:0)
谢谢大家。 正如@Rafael和@HasanTıngır提到的那样,问题出在$ VodDetail对象。 $ VodDetail并不包含所有视频的剧情属性。 因此,我通过替换以下代码对其进行了修复:
($VodDetail->plot)?$VodDetail->plot TO isset($VodDetail->plot)?$VodDetail->plot: