Laravel: "Fallback" Route to Cover "Any Other Route"

Laravel: "Fallback" Route to Cover "Any Other Route"

Laravel Daily

9 месяцев назад

4,739 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@n3storm
@n3storm - 04.10.2023 08:02

First commenter! Thankyou Povilas!

Ответить
@alex_nita
@alex_nita - 04.10.2023 08:07

Web.php can contain routes to "users". Bkw the {any?} will handle this case (together with the one with the post not found)?

Ответить
@julienSibille
@julienSibille - 04.10.2023 08:20

Isn't it the purpose of the last registered route of an app ?
Route::fallback(function () { return //whatever you need; });

Ответить
@valpuia604
@valpuia604 - 04.10.2023 08:35

I use firstOrFail() and no need abort_if()

Ответить
@JamesAutoDude
@JamesAutoDude - 04.10.2023 09:24

I went even further on this with my project a long time ago where it uses a "SlugController" and that processes this type of logic. That way it's more standard Laravel practice especially for looking up database items, but also to be more robust without bogging up the web.php route file

Ответить
@krunalshrimali4471
@krunalshrimali4471 - 04.10.2023 10:27

What is Route::feeds()?

Ответить
@junjettrasmonte
@junjettrasmonte - 04.10.2023 10:30

Hi Povilas, Is there any chance you can discuss about data residency and what is the best practice in Laravel? Basically laravel models that use different db connections in compliance with data protection and privacy regulations. How would you manage model relationships across multiple db connections? Thanks in advance. :)

Ответить
@vitalikartsivadze
@vitalikartsivadze - 04.10.2023 12:06

I would use ->firstOrFail() and remove abort_if() statement

Ответить
@abdullajonsharipov6504
@abdullajonsharipov6504 - 04.10.2023 12:49

replace abort_if to firstOrFail()

Ответить
@Flankymanga
@Flankymanga - 04.10.2023 18:37

Pretty neat

Ответить
@PerEriksson
@PerEriksson - 04.10.2023 23:16

Hello! You say ”302 for SEO purposes” but I guess you mean ”301”, which is the correct status code for permanent redirection :)

Ответить