findOrFail Laravel 8 method not found - php

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

Related

Laravel shopping cart package Model Associate issue

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

In ZF2, how can I register a custom Feed Reader extension?

I'm trying to register a Zend\Feed\Reader\Reader extension for working with Media RSS.
I followed the documentation, however I couldn't even get the extension to register.
This is the error I get:
Fatal error: Call to undefined method Zend\Feed\Reader\StandaloneExtensionManager::setInvokableClass() in ...
This is how I call the function:
if (!Reader::isRegistered('MrssService')) {
$extensions = \Zend\Feed\Reader\Reader::getExtensionManager();
$extensions->setInvokableClass('MrssService', 'Service\MrssService');
Reader::registerExtension('MrssService');
}
It seems that setInvokableClass() doesn't even exist for the object returned by Reader::getExtensionManager().
Any idea how to fix this?
If you are using zend-feed >= v2.6, there is another way to create custom extensions.
$extensions = new \Zend\Feed\Reader\ExtensionPluginManager();
$extensions->setInvokableClass('MrssService', 'Service\MrssService');
Reader::setExtensionManager(new \Zend\Feed\Reader\ExtensionManager($extensions));
Reader::registerExtension('MrssService');
BUT actually (v2.7) there is a little problem, that I reported here: https://github.com/zendframework/zend-feed/issues/29
When it will be solved, I will remove this notice on this post.
Meanwhile, if you want to use it, you can just fork and make the edit that I suggested in that Issue.

CakePHP Find on CakeSession Failing

I would like to read from the sessions table and display on a page in CakePHP. I can load the CakeSession model easy enough and even do a read on it, which works.
But when I do a find:
$sessions = $this->CakeSession->find('all');
I get this error:
Error: Call to undefined method CakeSession::find()
Any ideas on how to do a find on that model?
I created a model and it works, and didn't break anything else. Thanks for your help scrawler and dhofstet!

kohana 3.0.12 how to log

i am working on an website on kohana 3.0.12 and i have installed a module that loggs me some errors. All works fine, except that, when i want to effectively log an error, i get an error and i don;t know how to manage it.
Here is the messy code:
public static function handler(Exception $e)
{
// It's a nice time to log :)
Kohana::$log->add(Kohana::ERROR, Kohana_Exception::text($e));
etc code here
well that Kohana_Exception::text($e) causes an exception like: Call to undefined method Kohana_Exception::text() ? i guess it is a framework bug. any idea of how i can solve the problem? (i guess i should use another instance but Kohana_Exception:: but what instance?)
thank you
You get this error because neither Kohana_Exception nor Exception classes don't have text() method. I think the author of the module wanted to write like this:
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
I belive the exception handling in 3.0 is located in the Kohana class. Try Kohana::exception(), or look in api guide if that isn't it.

Zend AMF throwing InvocationTargetException

I am trying to make a service call to a php function from flex, through Zend AMF. Most of the functions get called fine, but for one particular function, it throws the following exception:
InvocationTargetException:There was an
error while invoking the operation.
Check your operation inputs or server
code and try invoking the operation
again.
Reason: Fatal error: Call to a member
function getInvokeArguments() on a
non-object in
D:\wamp\www\ZendFramework\library\Zend\Amf\Server.php
on line 328
I am not able to debug through this - has anyone faced any issue like this before, or have any ideas how this can be debugged?
At a quick glance through ZFW's source, this appears to be a bug on their framework.
// There is no check if $this->_table[$qualifiedName] is an object, implements an interface, extends a class, only if it's set (the key exists).
$info = $this->_table[$qualifiedName];
$argv = $info->getInvokeArguments(); // Here's when you get the error.
Source: http://framework.zend.com/code/filedetails.php?repname=Zend+Framework&path=/trunk/library/Zend/Amf/Server.php
I looked in their bug tracker and haven't found anything related to this, perhaps you should open a new issue?
Additionally, you can debug the problem by grabbing the message that Flex is sending to the PHP client and making a test case out of it.
We finally realized that this was a problem in the flex project setup - don't know exactly what it was, but once we deleted and created the project again, things started working fine!

Categories