【发布时间】:2018-04-19 16:25:07
【问题描述】:
我在 laravel 5.4 中创建了带有验证的脚本,但是我的错误没有显示出来。我尝试使用文档以另一种方式做到这一点,但效果是一样的。即使我尝试登录时出现错误也不起作用。我真的不知道发生了什么。你能帮助我吗?
在刀片中,我尝试显示如下错误:
@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;
}
}
好的,我做到了。删除: \Illuminate\Validation\ValidationException::class, 从 middlewareGroups 中的 App/Http/Kernel 并将其粘贴到同一文件中的 $middleware 中。
【问题讨论】:
-
您可以尝试查看源代码并检查错误是否已经生效。这可能是由您的 CSS 引起的并隐藏了您的错误。