Laravel 5.2 $errors未在Blade中出现
2022-08-30 14:03:20
因此,我正在遵循Laravel 5基础知识教程,并且我卡在表单验证上。我已经完全按照教程进行了操作,但是我得到了一个未定义的变量:我的创建文章视图中的错误。
在我正在学习的教程中,我在网上找到的内容,他们说错误变量总是在刀片文件中供您使用,所以我不知道我做错了什么?
任何帮助将不胜感激!爱拉拉维尔,除了这个错误!
View
@if($errors->any())
<ul class="alert alert-danger">
@foreach($errors->any() as $error)
<li>{{$error}}</li>
@endforeach
</ul>
@endif
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use App\Http\Requests;
use App\Http\Requests\UserRequest as UserRequest;
// use App\Http\Requests\CreateArticleRequest as CreateArticleRequest;
use App\Http\Controllers\Controller;
use Illuminate\View\Middleware\ErrorBinder;
class UserController extends Controller
{
public function create(){
return view('pages.signUp');
}
public function store(UserRequest $request){
User::create($request->all());
return 'the user has been registered!';
return view('user.profile');
}
}
请求验证
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class UserRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'email' => 'required|email',
'country' => 'required',
'password' => 'required|min:6',
'confirm_password' => 'required|same:password',
'height' => 'required',
'weight' => 'required',
];
}
}