I'm using Crinsane/LaravelShoppingcart package.
In my controller
Cart::add($request->id, $request->name, 1, $request->price)->associate('App\Product');
I've been associated Product model
and in view, I loop through it,
now if I die and dump it {{ dd($item->model->id) }} it works but without dd $item->model->id doesn't work instead gives error
Trying to get property 'id' of non-object
It sounds like the line you suspect of beeing the root for you error may not be the error that is shown. If you dd the code after this line is no longer executed therefore a potential access" to an id of non-object is also not executed. Take a look further down your code to see if the problem might be in a place that is executed after your dd location!
Additionally you could look into the laravel optional helper to catch the error and return a default value: https://laravel.com/docs/5.6/helpers#method-optional
Related
I am working on Laravel 8 , I have tried to use findOrFail method in order to set redirection to 404 error not found instead of displaying error but it is showing this error method findOrFail not found,
this is the line of code in ProfilesController that is causing the error
$user = User::findOrFail($user);
this is the output of the error
enter image description here
Thanks in advance,
Look like your code works fine. The issue Php Strom not able to identify methods.
I always use query() method to get autocomplete model methods
$user=User::query()->findOrFail($user);
or you might need to install any extension which can able to identify laravel methods
The problem is that I'm reciving Class 'session' not found error.
But the funny fact is that I'm not using session class. Anyway I'm using session namespace use Session;. I've found out that the problem occurs when I'm returning view.
If I return simple string or number it works, but when I use
return view('catering.prices')->with(['name' => 'Victoria']);
or
return view('greetings', ['name' => 'Victoria']);
I'm reciving the error.
Log:
[2016-10-06 11:38:54] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'session' not found' in D:\app\storage\framework\views\397c6d5694d7a10e04cabd271a3359cfd11a387e.php:16
Update
I'm seeing that it's not returning new views - I have now about 40 views. The old one are working well but when I create new views I'm reciving the error.
Answer
The problem was wrongly set permissions for specific user in my database. Thank you for your effort.
Anybody has some idea?
Try like this,
return view('catering.prices',['name'=> 'Victoria']);
OR
return view('catering.prices')->with('name', 'Victoria');
check here : https://laravel.com/docs/5.2/views
With errors like this:
ErrorException (E_UNKNOWN) Trying to get property of non-object
(View: /to/path/assign_template.blade.php)
How do I figure out line number where error is being produced?
In Laravel 4, on the left side you can click back down through the stack trace. Usually in views, 3-4 calls down will be the actual error that occurred in your view file.
That error is caused by trying to access the property of something that isn't an object, usually I find this is when trying to access relations to a model. Something like $model->relation->attribute. $model->relation in that case is usually null.
Im getting 2 errors. I saw that Jomsocial had the problem with their own site and fixed it but never posted how. Happens when you go to post an update in jomsocial and it locks up. You refresh the page and get
Error
Sorry, User ID not found.
with the following errors. Then you go login and check the profile and the update was posted fine.
Notice: JFactory::getUser(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/xxxxxxx/public_html/libraries/joomla/factory.php on line 244
Notice: CUser::CUser(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/xxxxxx/public_html/components/com_community/libraries/user.php on line 52
What version of JomSocial do you use? This issue shouldn't happen
I have the following Laravel 4.2 controller code in a store method:
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
I've tested this code with var_dump and the $validator is definitely returning the correct error messages.
The errors however are not being passed to the view. When attempting var_dump($errors) on the view I get the following exception
Undefined variable: errors.
I've also tried (by accident) var_dump($error)and it is of type object(Illuminate\Support\ViewErrorBag) however it does not contain any errors.
Does anyone know what the problem might be? Thanks in advance.
After looking into this issue for two whole days - I've finally fixed it! In the end I removed the vendor folder and ran composer update. I can only assume that something within Laravel was corrupt in the initial download.