Skip to main content

Middleware: Web and Spatie Check

Premium
3 min read

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?

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 46 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

E
ESPJustin ✓ Link copied!

When checking that the tables exist would it be better to use the config options that spatie use when creating the tables?

$tableNames = config('permission.table_names');
 
if (!Schema::hasTable($tableNames['roles']) || !Schema::hasTable($tableNames['permissions'])) {

This will allow for anyone who is already using the laravel-permission package and have alternative table names to still be able to use this package.

I have created a PR for this if you wanted to also include it in the final product.

PK
Povilas Korop ✓ Link copied!

Thank you Justin, fully agree and accepted the PR.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.