我在laravel 5.4中使用验证创建了脚本,但是我的错误没有显示。我尝试用另一种方式使用docs但效果是一样的。我尝试登录时的错误甚至都不起作用。我真的不知道发生了什么。你能帮助我吗?
在刀片中,我尝试显示错误:
@foreach ($errors->all() as $error)
{!! $errors->first() !!}
@endforeach
那是控制器:
public function addCooworkersSettings(Request $request)
{
$this->validate($request, [
'who_cooworker' => 'required|max:255',
]);
$user = Auth::user();
$data = ['user_id'=>$user->id,
'name'=>$request['who_cooworker']];
$cooworkers = Cooperator::create($data);
return view('user.settings.profile', compact('user'));
}
和型号:
class Cooperator extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'who_cooworker',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [];
/**
* Create a new instance after a validation.
*
* @param array $data
*/
public static function create(array $request = array())
{
$cooperator = new Cooperator;
$cooperator->user_id = $request['user_id'];
$cooperator->name = $request['name'];
$cooperator->save();
return $cooperator;
}
}
好的,我做到了。删除: \照亮\确认\ ValidationException ::类, 来自中间件组中的App / Http / Kernel并将其粘贴到同一文件中的$ middleware。
答案 0 :(得分:0)
在刀片中试试这个:
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
*假设您在视图中使用bootstrap *
答案 1 :(得分:0)
试试这个:
@foreach ($errors->all() as $error)
{{ $errors->first() }}
@endforeach
并检查页面源是否隐藏任何错误