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

amitdev's avatar

I am not able to debug this , can some body help

Screeen shot 1 : https://ibb.co/sK0szh3

Screeen shot 2 : https://ibb.co/F89NsCN

i have debug the $getTitle_Data->title using DD , the value is there but still $dataasset throws error

Error : Attempt to ready property title on null

$getTitle_Data = Assetwidget::WHERE('currentstatus','0') ->WHERE('id',$id) ->first();

   $dataasset =  $getTitle_Data->title ;

    return $dataasset ;
0 likes
4 replies
LaryAI's avatar
Level 58

It seems like you're encountering an issue where $getTitle_Data is null, which means that the query you're running is not returning any results. This could be due to the fact that there is no Assetwidget with a currentstatus of '0' and an id that matches the $id you're providing.

Here's how you can debug and handle this situation:

  1. Ensure that the $id variable is set correctly and that it corresponds to an existing record in your database.
  2. Check your Assetwidget model and database table to make sure that there is a record that matches the conditions you're querying for.
  3. Modify your code to handle the case where no record is found.

Here's an updated version of your code with added checks:

$getTitle_Data = Assetwidget::where('currentstatus', '0')
    ->where('id', $id)
    ->first();

if ($getTitle_Data) {
    $dataasset = $getTitle_Data->title;
} else {
    // Handle the case where no record was found
    // You could return a default value or throw an exception
    $dataasset = 'No title found for the given ID';
}

return $dataasset;

In this updated code, we first check if $getTitle_Data is not null before trying to access its title property. If $getTitle_Data is null, we set $dataasset to a default message or handle it as needed for your application.

Remember to replace the default message or handling with whatever is appropriate for your application's needs. If you expect a title to always be present, you might want to log this as an error or throw an exception instead of returning a default message.

1 like
kokoshneta's avatar

Please edit your question to post your actual code, not screenshots. You can format code by putting three backticks (```) on a separate line before and after the code block.

1 like
JussiMannisto's avatar

The $getTitle_Data variable is null when the app crashes. That's what the error says. I'm guessing your dd() doesn't crash because you're calling gettheData() multiple times, and on the first call $getTitle_Data is not null.

You should pay attention to variable and function naming. The names you've chosen don't make sense. Capitalization/underscore usage is also all over the place. Name variables by what they actually are, and functions by what they do. It'll make things easier.

2 likes
martinbean's avatar

@amitdev You’re calling ->first() when querying. This means it will return a model if there is a result, or null if there isn’t, which is what your error message is telling you:

Error : Attempt to ready property title on null

1 like

Please or to participate in this conversation.