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:
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.