S
S
sergei1792020-01-03 15:45:05
Laravel
sergei179, 2020-01-03 15:45:05

How to work with static routes and variables in Laravel?

I would also add the "curvature" tag, but maybe I won't miss it)

Hello everyone.

I understand Laravel 8 and there was a small problem.

Web.php has several routes that open different views at different addresses. There are requests that have a static address, for example:

Route::get('/basket/add', '[email protected]')->name('basket');

And there are requests with variable addresses, for example
Route::get('/{category}/{product?}', '[email protected]')->name('product');

So - for some reason, my dynamic addresses overlap the static ones. That is, when you enter in the address bar: localhost:8000/basket/add, it opens a view that should open when requested localhost:8000/{category}/{product?}

. I attribute this to the fact that dynamic addresses take everything that the user enters. But in theory, it should take only those addresses that are in the database, and there are 4 of them (mobile, pc, portable, othen), and should not overlap the static addresses that are specified in web.php.

There is also a problem with other addresses. The address:
Route::get('/{category}', '[email protected]')->name('category');

Overlaps address
Route::get('/place', '[email protected]')->name('basket-place');

However, the address
Route::get('/{category}', '[email protected]')->name('category');

For some reason it does not overlap the address:
Route::get('/categories', '[email protected]')->name('categories');

How can I fix this error and what can it be connected with?

I watch a video course on Laravel, but there was no such problem. Maybe due to the fact that Laravel is version 6 there, and I have version 8, maybe for some other reason. But I checked my code with the fact that in the video course - everything is the same.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-01-03
@sergei179

"Static" must be declared after "dynamic".

But in theory it should take only those addresses that are in the database
The router knows nothing about the contents of your database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question