How to Check String is URL or Not in Laravel?

By Hardik Savani November 5, 2023 Category : Laravel

Hi Folks,

Today, I will let you know example of laravel check string is url. if you want to see an example of how to check string is url or not in laravel then you are in the right place. you can see laravel string is url or not example. you'll learn laravel Str::isUrl() helper. Let's get started with laravel str isurl helper example.

The Str::isUrl() function in Laravel is used to check if the given string is a valid URL. Here is an example of how to use the Str::isUrl() function:

In this example, the Str::isUrl() function will return true if the $url string is a valid URL format, and false otherwise.

let's see the simple example:

Laravel Check String is URL or Not in Controller

you can use it with controller like this way:

Controller Code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Support\Str;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index(Request $request)

{

$isUrl = Str::isUrl('https://www.itsolutionstuff.com');

dd($isUrl);

}

}

Output:

true

Laravel Check String is URL or Not in Blade File

you can use it with blade file like this way:

Blade File Code:

<p>{{ Str::isUrl('https://www.itsolutionstuff.com') }}</p>

Output:

true

I hope it can help you...

Tags :
Shares