[Solved] Trying to get property of non-object error on laravel 5.4


Welcome to StackOverflow, yobab77! There’s a wonderful help article on how to ask questions here, that may help you get better assistance in the future.


ErrorException Trying to get property of non-object (View: C:\xampp\htdocs\bgcbus\resources\views\usercrud\sendView.blade.php)

This error indicates that the bug is coming from your sendView.blade.php view file, which you’ve stated has the following content:

TO veerify <a href="https://stackoverflow.com/questions/49351329/{{ route("sendEmailDone', ["email" => $user->email,"verifyToken"=>$user->verifyToken]) }}" click here />

The only object being accessed in this view is $user. Let’s see if we can figure out why it isn’t an object.

Your sendView view is being loaded through the verifyEmail Mailable. When loading a view via a Mailable, its view data can be pulled from the public properties of the Mailable. Your Mailable does have public $user; defined, so it should be sent to the view. So why isn’t it an object?

Assuming you’ve pasted the exact content of your Mailable, there appears to be a typo in your constructor:

public function __construct(User $user)
{
    //
    $this->userC=$user;
}

This is saving the supplied User object to the public property $userC, not $user.

Hopefully this simple typo is the root of your issue, and fixing it can let you continue developing your application. 🙂 Should that not be the case, please revise your question and add some additional details (again, see that help article for tips!).

solved Trying to get property of non-object error on laravel 5.4