armancs's avatar

How to fix 'errors' => object(ViewErrorBag)

please visit this link below:

https://gist.github.com/rajucs/a80a0f683b181cc5e3675928544f8d3e#file-how-to-fix-errorbag

thanks

0 likes
4 replies
tykus's avatar

Trying to get property of non-object means that you are expecting some variable to be an object, but it is not, e.g.

$user->name; // is $user is null, you will get this error

Usually this will happen if you use find() when getting a model, and it returns null. It is better to guard against this by using findOrFail() instead.

It can also happen whenever you are traversing relationships, but a related model is not available:

$user->friend->name // $user might be okay, but if friend relation is null then you get the error as well

You can guard against this using the optional()helper:

optional($user->friend)->name
armancs's avatar

Thanks @tykus for quick response

I am going fetch data from 2 table in one view. When i am dong two table query its showing me error. this is controller:

$programfees= UniversityAcademicModel::where('university_id',6645)->first();
    $uniinfo    = UniversityinfoModel::where('university_id',6645)->first();

and bypass these variable with compact. these two table have same foreign key id. should i make join query?

tykus's avatar

Does either of those queries result in null?

armancs's avatar
armancs
OP
Best Answer
Level 2

Problem solved when using get function in first query

$programfees= UniversityAcademicModel::where('university_id',6645)->get();
$uniinfo    = UniversityinfoModel::where('university_id',6645)->first();

@tykus thanks for your quick response.

Please or to participate in this conversation.