我想验证连接表。我只验证了一个表,但如果我有一个连接表怎么办?根据附图。我该如何验证呢?
public function store()
{
$input = Input::all();
$validation = Validator::make($input, User::$rules);
if ($validation->passes()){
User::create($input);
return View::make('users.create');
}
return Redirect::route('users.create')
->withInput()
->withErrors($validation)
->with('message', 'Please correct the following errors:');
}
答案 0 :(得分:0)
您可以使用许多验证器并验证UserAccount
型号:
public function store()
{
$input = Input::all();
$validation = Validator::make($input, User::$rules);
$validation2 = Validator::make($input, UserAccount::$rules);
$result = true;
if (!$validation->passes()) {
$result = false;
}
if (!$validation2->passes()) {
$result = false;
}
if ($result) {
User::create($input);
return View::make('users.create');
}
return Redirect::route('users.create')
->withInput()
->withErrors([$validation, $validation2])
->with('message', 'Please correct the following errors:');
}