Hai artisan, hari ini saya akan menunjukkan cara memvalidasi gambar dengan mudah di proyek laravel Anda.
larutan
$request->validate([
'file' => 'image'
]);
rute: rute/web.php
Route::get('form-create','FromController@index');
Route::post('form-store','FromController@store')->name('form.store');
Pengontrol: 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'
]);
}
}
Dapatkan kode lengkapnya: Contoh Validasi Gambar Laravel