Example 1 :
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
public function store(Request $request)
{
$validator = Validator::make($request->all(),[
"flight_title" =>'required',
"flight_name" => 'required',
"flight_detail" => 'required',
"flight_no" => 'required',
"flight_remark" => 'required',
]);
dd($request->fails());
dd($validator->validated());
}
public function store(Request $request)
$validator = Validator::make($request->all(),[
"flight_title" =>'required',
"flight_name" => 'required',
"flight_detail" => 'required',
"flight_no" => 'required',
"flight_remark" => 'required',
])->validateWithBag('postStore');
// dd($request->fails());
// dd($validator->validated());
}
@if ($errors->postStore->any())
{{ dd($errors->postStore->all()) }}
@endif
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
public function store(Request $request)
{
$validator = Validator::make($request->all(),[
"flight_title" =>'required',
"flight_name" => 'required',
"flight_detail" => 'required',
"flight_no" => 'required',
"flight_remark" => 'required',
]);
dd($request->fails());
dd($validator->validated());
}
public function store(Request $request)
$validator = Validator::make($request->all(),[
"flight_title" =>'required',
"flight_name" => 'required',
"flight_detail" => 'required',
"flight_no" => 'required',
"flight_remark" => 'required',
])->validateWithBag('postStore');
// dd($request->fails());
// dd($validator->validated());
}
@if ($errors->postStore->any())
{{ dd($errors->postStore->all()) }}
@endif
Example 2:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class DeceasedInformationRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
$postAttr = $this->request;
$rules = [
"status" =>'required',
"flight_title" =>'required',
];
if($postAttr->get('status')=='store') {
return $rules;
}
return [];
}
public messages() {
return [
'status.required' => 'Status is required!',
'flight_title.required' => 'Flight Title is required!',
];
}
public function attributes(){
return [
'status' => 'Status (*)',
'flight_title' => 'Flight Title(#)',
];
}
}
0 comments:
Post a Comment