she hates me
she hates me

Reputation: 1272

Why PhpStorm recognizes Laravel controller methods as unused?

I'm using PhpStorm 2019.2.1 to develop Laravel applications. I switched to this version from 9.3 and now it recognizes controller methods and classes as unused. (and provides quick fixes which doesn't help)

What might be the reason for that and how can I solve this?

Upvotes: 3

Views: 2845

Answers (2)

zxdx
zxdx

Reputation: 129

You can use PHPDoc @uses in your /routes/web.php

/**
* @uses App\Http\Controllers\SomeController::SomeMethod
*/

Route::get('/someRoute', 'SomeController@SomeMethod');

Upvotes: 8

Salim Djerbouh
Salim Djerbouh

Reputation: 11044

PhpStorm uses an indexer that looks for calls of your Controller classes and methods, it doesn't recognize the routing second argument because it's a string

Route::get('/someRoute', 'SomeController@SomeMethod');

While you can in theory make the controller class and methods static and call them like so

Route::resource('stuff', StuffController::class);

and

Route::get('/someRoute', SomeController::SomeMethod);

But it's better to either ignore or suppress those warnings

Upvotes: 1

Related Questions