Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Deekshith's avatar

Trying to use controller function in href tag action in laravel 8

I am trying to access controller function in action like below,

<a href="{{ action('AdminProjectController@getProjectDetail', $type,$project->id) }}">

it is giving below error,

Action AdminProjectController@getProjectDetail not defined
0 likes
4 replies
Nakov's avatar
Nakov
Best Answer
Level 73

@deekshith and in your controller you have:

public function getProjectDetail($type, $project)
{
}

?

You can try to use the full namespace of the controller as well: App\Http\Controllers\AdminProjectController@getProjectDetail.

I would personally name the route in the web.php or wherever you defined it and use the named route instead of action here:

Route::get(...)->name('project.details');

and use route('project.details', params) in the view.

thinkverse's avatar

Routes for controller actions still need to be defined in your web.php routes file before you can use action(). Otherwise, the internals won't know which route to actually generate.

Then you need to use the full namespace as @nakov said.

// web.php
use App\Http\Controllers\AdminProjectController;

Route::get('/details/{type}/{project}', [AdminProjectController::class, 'getProjectDetail']);

This will create an internal key for this route that you can then access using the action() function.

<a href="{{ action('App\Http\Controllers\AdminProjectController@getProjectDetail', [$type, $project->id]) }}">

The parameters you want to pass to your route also need to be inside an array, since the third parameter expects a boolean argument, as defined in the declaration.

public function action($action, $parameters = [], $absolute = true)

Hope that helps. 🙂

1 like
Deekshith's avatar

@thinkverse Thank you. i was thinking to avoid including full path to access controller function. Thank you will follow this.

Please or to participate in this conversation.