mirror of
https://github.com/10h30/Test-Laravel-Validation.git
synced 2026-06-05 15:07:56 +09:00
32 lines
636 B
PHP
32 lines
636 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Product;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
public function create()
|
|
{
|
|
return view('products.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'name' => 'required',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return redirect('products/create')
|
|
->withErrors($validator);
|
|
}
|
|
|
|
Product::create($validator->validated());
|
|
|
|
return 'Success';
|
|
}
|
|
}
|