Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Are href="{{ url('articles') }}" and href="{{ route('articles') }}" doing the same thing?

I have this code

<a class="dropdown-item" href="{{ url('articles') }}">My articles</a>

it works fine, but I’ve seen in the documentation and other refs that we can use route instead of url():

<a class="dropdown-item" href="{{ route('articles') }}">My articles</a>

but it didn’t work for me.
what is the difference between them and why it didn’t work for me?
here is my route definition:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Route::resource('articles', ArticlesController::class); // generated by artisan command

>Solution :

Both generate URLs under the hood. The difference being url generates it based on the provided path whereas route generates it based on the name of the route provided.

The reason your route has not worked is because there is no route named articles. Route::resource generates the routes for you, but the route you most likely want to reference is articles.index.

<a class="dropdown-item" href="{{ route('articles.index') }}">My articles</a>

You can use php artisan route:list to see all the available routes in your application.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading