ItSolutionStuff.com

How to Check String is URL or Not in Laravel?

By Hardik Savani • November 5, 2023
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: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Convert String to CamelCase in Laravel?

Read Now →

How to Get Length of String in Laravel?

Read Now →

Laravel Convert String to Uppercase Example

Read Now →

Laravel Convert String to Lowercase Example

Read Now →

Laravel Import Large CSV File Using Queue Example

Read Now →

How to Replace String in Laravel?

Read Now →

How to Install and Setup Supervisor in Ubuntu for Laravel?

Read Now →

Laravel String Contains Case Insensitive Example

Read Now →

Laravel Stripe Checkout Payment Integration Example

Read Now →

How to Convert String to Array Conversion in Laravel?

Read Now →

How to Add Dynamic Carousel Slider in Laravel?

Read Now →

How to Install and Use Laravel Debugbar?

Read Now →

Laravel PayPal Send Payment to Email Example

Read Now →