Laravel image validation example

devcse

devcse

Posted on July 21, 2021

Laravel image validation example

Hi artisan, today I will show you how to validate images in your laravel project easily.

Solution

$request->validate([
   'file' => 'image'
]);
Enter fullscreen mode Exit fullscreen mode

Route : routes/web.php

Route::get('form-create','FromController@index');
Route::post('form-store','FromController@store')->name('form.store');

Enter fullscreen mode Exit fullscreen mode

Controller : app/Http/Controllers/ImgController.php

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

use Illuminate\Support\Facades\Blade;
use App\Models\User;
use App\Models\Post;

class FromController extends Controller
{   

    public function create()
    {
        return view('form');
    }


    public function store(Request $request)
    {
        $request->validate([
           'file' => 'image'
        ]);
    }
}

Enter fullscreen mode Exit fullscreen mode

GET FULL CODE: Laravel image validation example

💖 💪 🙅 🚩
devcse
devcse

Posted on July 21, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related