Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mbilal's avatar

Laravel Modal->save() it says Undefined property: stdClass::$plot

I am getting this weird error, and trying to fix that from last 2 days. Please help me, thanks in advance. NOTE: dd($video,$VodDetail,$tmdb ); all are set and have required details.

$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();

If I put dd($article); before $article-save(); it gives me following result:

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"
  ]
  #connection: null
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #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, dedicates his time to narrate the adventures of Pepe Frituras, one of the most renowned Mexican dancers who lost his freedom due to a night of partying. Precisely for that reason it ends up in a more dangerous penitentiary. However, through stories that integrate music and dances, he will tell of his exploits and how he ended up being the prisoner who achieved freedom through his imagination."
    "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"
  ]
  #original: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #events: []
  #observables: []
  #relations: []
  #touches: []
  #hidden: []
  #visible: []
  #guarded: array:1 [
    0 => "*"
  ]
}
0 likes
9 replies
aurawindsurfing's avatar

There is no such property on your object:

$VodDetail->plot

Did you define plot? try dd($VodDetail) or even dd($VodDetail->plot) and see if you have it in first place.

You can not check if it is empty or null if it does not exist.

Hope it helps!

Mbilal's avatar

@aurawindsurfing $VodDetail->plot property exist I checked that's why it's putting value in $article->description.

aurawindsurfing's avatar

No it does not ;-)

it says Undefined property: stdClass::$plot

try saving it with this one:

$article->description = '';

Does it work?

Mbilal's avatar

@aurawindsurfing dd($VodDetail);

{#928
  +"kinopoisk_url": "https://www.themoviedb.org/movie/518326"
  +"name": "Sacudete Las Penas"
  +"o_name": "Sacudete Las Penas"
  +"cover_big": "http://axetv.net:25461/images/bq2MQCJTyCFdw8QraEMgBpuQvQ4_big.jpg"
  +"movie_image": "http://axetv.net:25461/images/bq2MQCJTyCFdw8QraEMgBpuQvQ4_small.jpg"
  +"releasedate": "2018-04-27"
  +"episode_run_time": 0
  +"youtube_trailer": "5jstm_JeyW8"
  +"director": ""
  +"actors": ""
  +"cast": ""
  +"description": "One of the prisoners who have to spend a long season in jail, González, dedicates his time to narrate the adventures of Pepe Frituras, one of the most renowned Mexican dancers who lost his freedom due to a night of partying. Precisely for that reason it ends up in a more dangerous penitentiary. However, through stories that integrate music and dances, he will tell of his exploits and how he ended up being the prisoner who achieved freedom through his imagination."
  +"plot": "One of the prisoners who have to spend a long season in jail, González, dedicates his time to narrate the adventures of Pepe Frituras, one of the most renowned Mexican dancers who lost his freedom due to a night of partying. Precisely for that reason it ends up in a more dangerous penitentiary. However, through stories that integrate music and dances, he will tell of his exploits and how he ended up being the prisoner who achieved freedom through his imagination."
  +"age": "+"
  +"rating_mpaa": ""
  +"rating_kinopoisk": 10
  +"rating_count_kinopoisk": 1
  +"country": "Mexico"
  +"genre": "Drama"
  +"backdrop_path": []
  +"tmdb_id": 518326
  +"duration_secs": 5117
  +"duration": "01:25:17"
  +"video": {#927
    +"index": 0
    +"codec_name": "h264"
    +"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"
    +"profile": "High"
    +"codec_type": "video"
    +"codec_time_base": "6150129/294911282"
    +"codec_tag_string": "avc1"
    +"codec_tag": "0x31637661"
    +"width": 1280
    +"height": 536
    +"coded_width": 1280
    +"coded_height": 536
    +"has_b_frames": 2
    +"sample_aspect_ratio": "16013:16000"
    +"display_aspect_ratio": "239:100"
    +"pix_fmt": "yuv420p"
    +"level": 41
    +"color_range": "tv"
    +"color_space": "bt709"
    +"color_transfer": "bt709"
    +"color_primaries": "bt709"
    +"chroma_location": "left"
    +"refs": 1
    +"is_avc": "true"
    +"nal_length_size": "4"
    +"r_frame_rate": "24000/1001"
    +"avg_frame_rate": "147455641/6150129"
    +"time_base": "1/90000"
    +"start_pts": 0
    +"start_time": "0.000000"
    +"duration_ts": 460540080
    +"duration": "5117.112000"
    +"bit_rate": "1140625"
    +"bits_per_raw_sample": "8"
    +"nb_frames": "122688"
    +"disposition": {#926
      +"default": 1
      +"dub": 0
      +"original": 0
      +"comment": 0
      +"lyrics": 0
      +"karaoke": 0
      +"forced": 0
      +"hearing_impaired": 0
      +"visual_impaired": 0
      +"clean_effects": 0
      +"attached_pic": 0
      +"timed_thumbnails": 0
    }
    +"tags": {#925
      +"language": "und"
      +"handler_name": "VideoHandler"
    }
  }
  +"audio": {#922
    +"index": 1
    +"codec_name": "aac"
    +"codec_long_name": "AAC (Advanced Audio Coding)"
    +"profile": "LC"
    +"codec_type": "audio"
    +"codec_time_base": "1/48000"
    +"codec_tag_string": "mp4a"
    +"codec_tag": "0x6134706d"
    +"sample_fmt": "fltp"
    +"sample_rate": "48000"
    +"channels": 2
    +"channel_layout": "stereo"
    +"bits_per_sample": 0
    +"r_frame_rate": "0/0"
    +"avg_frame_rate": "0/0"
    +"time_base": "1/48000"
    +"start_pts": 0
    +"start_time": "0.000000"
    +"duration_ts": 245621760
    +"duration": "5117.120000"
    +"bit_rate": "191373"
    +"max_bit_rate": "191373"
    +"nb_frames": "239865"
    +"disposition": {#921
      +"default": 1
      +"dub": 0
      +"original": 0
      +"comment": 0
      +"lyrics": 0
      +"karaoke": 0
      +"forced": 0
      +"hearing_impaired": 0
      +"visual_impaired": 0
      +"clean_effects": 0
      +"attached_pic": 0
      +"timed_thumbnails": 0
    }
    +"tags": {#4038
      +"language": "spa"
      +"handler_name": "SoundHandler"
    }
  }
  +"bitrate": 1338
} 

dd($VodDetail->plot);

"One of the prisoners who have to spend a long season in jail, González, dedicates his time to narrate the adventures of Pepe Frituras, one of the most renowned Mexican dancers who lost his freedom due to a night of partying. Precisely for that reason it ends up in a more dangerous penitentiary. However, through stories that integrate music and dances, he will tell of his exploits and how he ended up being the prisoner who achieved freedom through his imagination."
aurawindsurfing's avatar

OK looks like not all of the movies have a plot, have a look at your first example:

"title" => "Sacudete Las Penas"
    "description" => "One of the prisoners who have to spend a long season in jail, González, dedicates his time to narrate the adventures of Pepe Frituras, one of the most renowned Mexican dancers who lost his freedom due to a night of partying. Precisely for that reason it ends up in a more dangerous penitentiary. However, through stories that integrate music and dances, he will tell of his exploits and how he ended up being the prisoner who achieved freedom through his imagination."
    "releaseDate" => "2018"

No plot here.

So try doing:

$article->description = isset($VodDetail->plot) ? $VodDetail->plot : ($tmdb->overview) ?$tmdb->overview : '';

Hope it helps!

Mbilal's avatar

@aurawindsurfing

$article->description = ($VodDetail->plot) ? $VodDetail->plot : ($tmdb->overview) ?$tmdb->overview : '';

that's already in my code, have a look in 1st code snippet.

aurawindsurfing's avatar
Level 50

yes but:

($VodDetail->plot)

is not the same as

isset($VodDetail->plot)

You can not check if something is true or false if it does not exists

Please or to participate in this conversation.