K
K
Kamol2016-02-03 20:30:36
Web development
Kamol, 2016-02-03 20:30:36

Validation for multiple Request - e and their simultaneous verification?

Good day.
There is a model A and B.
relashionship: A hasMany B
Each model has validation rules in the Request.

class ARequest extends Request {

    public function rules()
    {
        //правила
    }
}

class BRequest extends Request {

    public function rules()
    {
        //правила
    }
}

In the AController controller, you need to make a type like this:
public function store(ARequest $request, BRequest $request2)
{
   <b> //как здесь валидировать оба Request при этом валидация срабатывалась одновременно ,
   //а не так чтобы сначала выполнилась валидация A потом B</b>
   
}

Or how is validation of two objects in one controller done, while strictly using Request Validation to avoid duplication of validation rules?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fet, 2016-02-03
@halenharper

A bit unclear.
Are you talking about saving user profile edit form data?
If so, then I don’t understand what prevents the form data for validation from being added to one Request?
The fields are all named differently, there will be no duplication.
And after the melon data arrives in the User controller, save everything to the necessary tables.

public function store_user(UserRequest $request)
{
$user = new User();
$user-> login = $request['login];
//....
$user->save();

$address = new AddressBook();
$address-> full_name = $request['full_name];
//....
$address->save();
//ну или
$user = User::create($request->all());
$address_book = AddressBook::create($request->all());
//по идее тоже должно сработать
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question