How to validate website url in laravel using validaiton

Updated at 14-Aug-2021, By samar

How to validate website url in laravel using validaiton

In this session, we’ll try our hand at solving the "How to validate website url in laravel using validaiton" puzzle by using the computer language.

You can validate the website URL in laravel using validation. You have to pass the url rule to input name to avoid the invalid website URL in laravel.
  • URL validation in laravel

    public function store(Request $request){
        $request->validate([
            'website' => 'required|url',
        ]);
    }
    

    You can validate a website URL in laravel using url rule in validate() method.

  • Laravel URL validation with https using regex

    //Inside controller's method
    $regex = '/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/';
    $request->validate([
        'url' => 'required|regex:'.$regex,
    ]);
    

Back to code snippet queries related laravel