Controller not found Hello, I have a problem: my controller AvatarController is not found.
His namespace is App\Http\Controllers\User.
I have tried to use him with action('AvatarController@method') and action('User\AvatarController@method').
But with them, I get the error: Action App\Http\Controllers\AvatarController@getUserAvatar not defined. and Action App\Http\Controllers\User\AvatarController@getUserAvatar not defined.
Thanks
try
action('User\AvatarController@method')
I have already tried this.
Here is my action:
<img src="{{ action('User\AvatarController@getUserAvatar', ['name' => $name]) }}" />
And here is my AvatarController:
class AvatarController extends Controller
{
protected function getUserAvatar($name)
{
try {
$user = (new User)->where('name', '=', $name)->firstOrFail();
} catch (ModelNotFoundException $exception) {
return $this->getRandomAvatar();
}
return 'storage/' . $user->avatar;
}
}
Add the namespace lines to the post above so we can see
What is the folder structure and file name?
Your function is protected not public. Protected functions are only visible to same class or a class that extends it.
Avatar Controller with the namespace (without uses):
namespace App\Http\Controllers\User;
class AvatarController extends Controller
{
protected function getUserAvatar($name)
{
try {
$user = (new User)->where('name', '=', $name)->firstOrFail();
} catch (ModelNotFoundException $exception) {
return $this->getRandomAvatar();
}
return 'storage/' . $user->avatar;
And here is the structure: http://prntscr.com/k3wmiu
Change
protected function getUserAvatar($name)
to
public function getUserAvatar($name)
This is the same error.. Action App\Http\Controllers\User\AvatarController@getUserAvatar not defined.
Have you run composer dump recently?
you need to run it if you change the name or namespace of a class
After the command, I have the same error...
Inside my IDE, I need to redownload all files?
I call my controller inside a blade file. Is it a problem?
no, using action inside blade is not a problem
you changed protected to public?
What is your current error message?
I have my function from protected to public.
My error message is Action App\Http\Controllers\User\AvatarController@getUserAvatar not defined. (View: /var/www/html/resources/views/emails/verifyuser.blade.php)
Do you have a route corresponding to that action?
its not possible to create action in your blade if there is no route to map to
Please sign in or create an account to participate in this conversation.