1
votes

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.

2
You can try to view source and check on that if the error is working already. It's maybe caused of your CSS and hides your errors.Nguyen Hoang

2 Answers

0
votes

try this in blade:

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif  

* assuming you use bootstrap in your views*

0
votes

try this :

@foreach ($errors->all() as $error)
   {{ $errors->first() }}
@endforeach

and check the page source whether there are any errors hidden