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
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
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
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.
Is there any way to dispatch an event and call a method when an error is occurred in joomla same as Zend ? I want to log those error in log file. I want to use a single method to catch every error. is it possible ?
Is there any other way to do this except JError, Please suggest.
To log errors to a file, you can use the following:
jimport('joomla.log.log');
// Log errors to specific file.
JLog::addLogger(
array(
'text_file' => 'mod_mymodule.errors.php'
),
JLog::ALL,
'mod_mymodule'
);
This will create the following and store all error there:
root/logs/mod_mymodule.errors.php
You can of course change mod_mymodule to whatever you wish.
Hope this helps
If I understand your question right you can use JError class to get this done. You can raise error and handle them.
I am using Laravel 4 for a project I am working on. I need to retrieve the first comment from the post. I use the following code to do so.
$comments = Comment::where('post_id', $post->id)->first();
This successfully retrieves the first comment (I know that because I print_r-ed $comments and it returned all the right information).
However, the following line of code triggers the error __toString() must not throw an exception
<td>{{$comments->content}}</td>
When I print_r-ed that it returned type string, and returned the correct string as well. Why then would it even try to convert $comments->content to type string when it is already a string?
Based off the information you've given and my experience with Laravel I'd bet that the line of code causing the exception is not the line you've put in your question.
<td>{{$comments->content}}</td>
This exception is complaining about the view throwing an exception. If this particular line was the issue you'd get a more descriptive exception about how $comments->content can't be converted into a string. You've also already tested that it is indeed a string.
I'd recommend finding where your "View" object is being echoed to the view and change it like so.
{{ View::make('yourbladefile')->__tostring() }}
This worked for me by providing a more accurate and informative exception. For more info on your exception you should check out Why it's impossible to throw exception from __toString()?
It's what gave me the idea in the first place. I know it's not a perfect answer so please let me know if this works and I'll update my answer if this turns out not be the case. Good luck.
I know that this is an old question, but for future googlers (like me) there is another way to solve that error, and it is independent of your framework:
public function __toString()
{
try {
return (string) $this->attributeToReturn; // If it is possible, return a string value from object.
} catch (Exception $e) {
return get_class($this).'#'.spl_object_hash($this); // If it is not possible, return a preset string to identify instance of object, e.g.
}
}
You can use it with your custom class with no framework, or with an entity in Symfony2/Doctrine... It will work as well.