I created script with validation in laravel 5.4 but there my errors are not showing. I tried to do it in another way using docs but effect is the same. Even errors when I try to login doesn't work. I really don not know what happened. Can you help me?
In blade I try to display errors it like:
@foreach ($errors->all() as $error)
{!! $errors->first() !!}
@endforeach
That is controller:
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'));
}
and model:
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;
}
}
Okay I did it. Delete: \Illuminate\Validation\ValidationException::class, from App/Http/Kernel in middlewareGroups and paste it to $middleware in the same file.