mirror of
https://github.com/10h30/Test-Laravel-Validation.git
synced 2026-06-05 15:07:56 +09:00
Task 3 - errors shown in validation Blade
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Project;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
public function create()
|
||||
{
|
||||
return view('projects.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'description' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect('projects/create')
|
||||
->withErrors($validator);
|
||||
}
|
||||
|
||||
Project::create($validator->validated());
|
||||
|
||||
return 'Success';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user