从请求重定向到同一页面(不工作)。 laravel 5.4
From request redirecting to same page (not working). laravel 5.4
我正在使用名为 StoreAdminRequest 的请求来验证我的表单,但没有任何反应。它重定向到同一页面。我不知道怎么了。但是,当我在 rules() 函数中添加时,它确实进入了该函数。
StoreAdminRequest.php
namespace App\Http\Requests\Admin;
use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreAdminRequest.
*/
class StoreAdminRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
// return access()->hasRoles([2,6]);
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'first_name' => 'required|max:191',
'last_name' => 'required|max:191',
'email' => 'required', 'email', 'max:191', Rule::unique('users','email'),
'mobile' => 'required'
];
}
}
AdminController.php
public function store(StoreAdminRequest $request)
{
$admin = $this->_admin->create($request->all());
}
如果您只是想重定向到不同的路线,您应该使用
return redirect()->route('/desired/route/to/redirect');
在您的控制器中。
您的实际问题是由于缺少 RedirectResponse 导致的,无法更改您从服务器获得的所需页面。如果没有定义其他路由,您将始终被重定向到您发出请求的页面。
我需要遍历 $errors 变量。谢谢
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
我正在使用名为 StoreAdminRequest 的请求来验证我的表单,但没有任何反应。它重定向到同一页面。我不知道怎么了。但是,当我在 rules() 函数中添加时,它确实进入了该函数。
StoreAdminRequest.php
namespace App\Http\Requests\Admin;
use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreAdminRequest.
*/
class StoreAdminRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
// return access()->hasRoles([2,6]);
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'first_name' => 'required|max:191',
'last_name' => 'required|max:191',
'email' => 'required', 'email', 'max:191', Rule::unique('users','email'),
'mobile' => 'required'
];
}
}
AdminController.php
public function store(StoreAdminRequest $request)
{
$admin = $this->_admin->create($request->all());
}
如果您只是想重定向到不同的路线,您应该使用
return redirect()->route('/desired/route/to/redirect');
在您的控制器中。
您的实际问题是由于缺少 RedirectResponse 导致的,无法更改您从服务器获得的所需页面。如果没有定义其他路由,您将始终被重定向到您发出请求的页面。
我需要遍历 $errors 变量。谢谢
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif