I use laravel 5.6
I use https://laravel.com/docs/5.6/validation#form-request-validation to validation server side
My controller like this :
<?php
....
use App\Http\Requests\UserUpdateRequest;
class UserController extends Controller
{
...
public function update(UserUpdateRequest $request)
{
// dd($request->all());
}
}
Before run statement in the update method, it will call UserUpdateRequest to validation server side
The validation like this :
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserUpdateRequest extends FormRequest
{
....
public function rules()
{
dd($this->request->all());
return [
'name' => 'required|max:50',
'gender' => 'required',
'birth_date' => 'required',
'address' => 'required',
'status' => 'required'
];
}
}
The result of dd($this->request->all()); like this :
Array
(
[selected_data] => {"name":"agis","gender":"2","birth_date":"2018-03-13","address":"london"}
)
How can I validation if the data is object array like that?
You can use a dot notation like so:
public function rules()
{
return [
'selected_data.name' => 'required|max:50',
'selected_data.gender' => 'required',
'selected_data.birth_date' => 'required',
'selected_data.address' => 'required',
'selected_data.status' => 'required',
];
}
Read more about it here: Validating Array.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With