How to check if current url is valid in laravel?

by arnoldo.moen , in category: PHP Frameworks , 4 months ago

How to check if current url is valid in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 20 days ago

@arnoldo.moen 

In Laravel, you can use the URL::isValidUrl() method to check if a given URL is valid. Here's an example of how to check if the current URL is valid:

1
2
3
4
5
6
7
8
9
use IlluminateSupportFacadesURL;

$currentUrl = URL::current();

if (URL::isValidUrl($currentUrl)) {
    echo "The current URL is valid.";
} else {
    echo "The current URL is not valid.";
}


This code will check if the current URL is valid and display a message accordingly.