mirror of
https://github.com/10h30/Test-Laravel-Validation.git
synced 2026-07-11 19:05:53 +09:00
Task 8 - customize validation messages
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreBuildingRequest;
|
||||
use App\Models\Building;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class BuildingController extends Controller
|
||||
{
|
||||
public function create()
|
||||
{
|
||||
return view('buildings.create');
|
||||
}
|
||||
|
||||
// TASK: Customize the validation error message to say "Please enter the name"
|
||||
public function store(StoreBuildingRequest $request)
|
||||
{
|
||||
Building::create($validator->validated());
|
||||
|
||||
return 'Success';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
// TASK: Customize the validation error message to say "Please enter the name"
|
||||
class StoreBuildingRequest extends FormRequest
|
||||
{
|
||||
protected $redirectRoute = 'buildings.create';
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Building extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name'];
|
||||
}
|
||||
Reference in New Issue
Block a user