Tell me, I'm looking for a specific entry in laravel: Information::where("url",$url)->first(); (belongsTo connection) And I try to appeal to the genus in this way. table:

 dump($dataPage->user->email); 

And in the end it gives out: Trying to get property of non-object

And when I search through: Information::find($url) (this is if I specify the url from numbers), it finds and everything works. Tell me what could be the problem?

    1 answer 1

    Try using Information::with('user')->first();

    And in order to avoid errors, the helper optional();

    https://laravel.com/docs/5.6/helpers#method-optional

    https://laravel.com/docs/5.6/eloquent-relationships#eager-loading