Courses

How to Create Laravel Package: Step-by-Step Example

Now, if you try to click Add Role, you will get an error Undefined variable $errors

That variable comes from the default Validation mechanism, exactly as the Laravel documentation says.

packages/laraveldaily/laravel-permission-editor/resources/views/roles/create.blade.php:

// ...
 
<div class="sm:max-w-md px-6 py-4">
 
@if ($errors->any())
<div class="text-red-500 text-sm mb-4">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
 
<form action="{{ route('permission-editor.roles.store') }}" method="POST">
@csrf
<div>
// ...

So if Laravel docs say that validation error should come automatically, why is it not defined as a variable?

This lesson is only for Premium Members.
Want to access all lessons of this course?

You also get:

  • 58 courses (1056 lessons, 44 h 09 min total)
  • Premium tutorials
  • Access to repositories
  • Private Discord