Next on our list - separating user roles. In our system, we need admins to manage the system settings and employees, while the employees themselves can only manage customers and nothing else:

In this lesson, we will do the following:
- Create roles Model and Database structure
- Create a user management page (CRUD)
- Add employees to our Customers' table and form for admins to manage
- Add employee changes to our customer history
- Add an additional tab in Customers for
My Customers- customers assigned to the employee
Creating Roles Model and Database structure
Let's start by creating our migration file:
Migration
Schema::create('roles', function (Blueprint $table) { $table->id(); $table->string('name'); $table->timestamps();});
Then, we can fill out our Model:
app/Models/Role.php
class Role extends Model{ protected $fillable = ['name'];}
Of course, we should also...
app/Models/Customer.php
Looks like this line should be:
app/Filament/Resources/CustomerResource/Pages/ListCustomers.php
with filter query:
Correct, updated it! Sorry about that
Hi! Thank you and the team for the amazing work! Just a quick questions if i may.
in the following example, shouldn't the code be:
Since we're only looking for records where employee_id is not null which may result in $lastLog being null.
Maybe im wrong tho. Keep up the good work!
Hi, this was updated yesterday as indeed - there was a mistake on our end!
We also fixed My Customers tab filtration
Oh for me it still says "$lastLog->employee_id" without the nullsafe operator. But thank you for confirming!
Hm, did you encounter an issue with nullsafe? I have not seen it, so did not add it! But definitely can add a check for it
i did encounter a problem without using the nullsafe on $lastLog->employee_id. In the course it says to use "$lastLog->employee_id" but i think it should say "$lastLog?->employee_id"
But maybe i did something wrong before this.
Hm... Maybe I had a different structure there and didn't see the issue. In any case, added a check! Thanks for reporting
Could we simplify using:
I choose Blue_Moonie solution, is more clear and work. The alternative is to modify the seeder and associate, during the creation of the customer, an employee (a solution I do not like)