Cannot resolve file/directory for routes
I've already marked the `public` directory as a Resource Root, so PhpStorm has no trouble finding `/js/app.js` and `/images/cool.png` for `href` attributes, but it still shows errors when linking to URLs served by routes (Laravel in this case). Is there a metadata file format for specifying additional valid URL structures? I'd be happy to build a package to parse Laravel's route files and generate that metadata if so.
As a stopgap solution, I created the matching directory hierarchy under `resources/urls` and marked it as an additional Resource Root. It works as far as hacks go, but there's no way developers will keep it up-to-date.
resources/
urls/
about/
api/
load-gallery
mark-viewed
contact/
news/
auto-shows
industry
photos/
...
Please sign in to leave a comment.
Hi there,
Nope (no metadata file). But you may try htaccess (rewrite rules, not sure if mode_rewrite or something more simpler) -- I've heard that it should.
Otherwise you may just disable that inspection that generates such warnings.
At the same time -- they are routes .. in Laravel framework. So why not use "{{ route('route.name.here') }}" in links? You would need to use named routes for this, of course. Or .. if those are just URLs ... {{ url('your/url/here') }}
Thanks, Andriy. Yes, we use `Route::make(...)` for most links, but the navbar and footer have a lot of simple hard-coded links to various news tag pages, contact us, etc. It seems overkill to name the route and use the accessor just to create a simple route. I'd prefer `/contactus` to `{{ Route::make('contact-us') }}`, partly for readability but honestly a bit for premature optimization since these are built on every page.
Could you please give a small example of using a `.htaccess` file for this? I just need to tell PhpStorm that `/contactus` is a valid URL, but I don't know enough about writing htaccess rules to come up with a solution using it. And, of course, this is only to satisfy PhpStorm's inspector—not Apache.
>Yes, we use `Route::make(...)` for most links, but the navbar and footer have a lot of simple hard-coded links to various news tag pages, contact us, etc. It seems overkill to name the route and use the accessor just to create a simple route.
The choice is yours. Plus it may depend on how you actually handle your routes etc. In my code every page has named route so I simply do not have such issues. Tiny overhead and no headaches with URL changes etc (P.S. I also use standard route() function and not Route::make())
>Could you please give a small example of using a `.htaccess` file for this?
As I have said there -- "I've heard". Never tired myself as frameworks have own routing these days.
I believe it was this ticket: https://youtrack.jetbrains.com/issue/WI-31585
Ah yes, I checked, and we're using `route()` as well. You're right that the overhead is probably negligible given that the routes have already been parsed and built. It's just a lookup and parameter injection.
No worries, I'll check out that ticket and do some research. Thanks for the tip and your advice. :)