Laravel validates an input as URL type and checks this url exists or not

In this tutorial we will discuss what is use of laravel active_url validation. how to validate input is url in laravel. how to check input url is valida or not.

here we differentiate laravel simple url active_url validation.



Laravel URL validation

Laravel URL validation check input field is url or not it check valid url with http. so when you use input url then take URL validation

App/Http/Controllers/FrontController.php
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;

class FrontController extends Model
{
  public function store(Request $request) {
    $validation = Validator::make($request->all(), [
      'url' => 'required|url'
    ]);

    if($validation->fails()){
      return $validation->errors();
    }
  }
}

Laravel active_url validation

When you want to check whether a URL is real or not then use active_url, Active URL validation also checks given domain is active or not. active_url validation check input URL must have A or AAAA record according to the dns_get_record PHP function.

App/Http/Controllers/FrontController.php
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;

class FrontController extends Model
{
  public function store(Request $request) {
    $validation = Validator::make($request->all(), [
      'url' => 'required|active_url'
    ]);

    if($validation->fails()){
      return $validation->errors();
    }
  }
}

Laravel url vs active_url validation

The difference between a URL and an active URL is URL only checks the URL format is right not and an active URL validates the URL format and corrects the running/active URL.

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links