JamesTechDude
JamesTechDude
Explore posts from servers
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/20/2023 in #💡filament
Making tabs for edit page
Sadly I decided to go away from Filament 😦 it's very nice, but I have very custom pages and would have to learn custom page logic to get those to work again haha. But it was fun to play with! I may bug you in the Laravel section someday soon tho 😅
10 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/20/2023 in #💡filament
Making tabs for edit page
THAT WORKS! Thank you!
10 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/20/2023 in #💡filament
Making tabs for edit page
I made a view action using: php artisan make:filament-page ViewLitter --resource=LitterResource --type=ViewRecord But the problem is, this still generates the form at the top - just with a view only type / disabled fields, with no way to hide it that I can find in the documentation I'll try messing around further
10 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/20/2023 in #💡filament
Making tabs for edit page
That might be the way to go 🤔 and just put the relationship manager onto its own page?
10 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/15/2023 in #💡filament
How to check user roles in canAccessPanel()
Disregard, it was VS Code giving this error even though it's working... intelliphense (or whatever) for ya
55 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/15/2023 in #💡filament
How to check user roles in canAccessPanel()
In my User model, I have:
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}

public function hasRole($userRoles)
{
if (is_array($userRoles)) {
$roles = $this->roles->whereIn('name', $userRoles);
} else {
$roles = $this->roles->where('name', $userRoles);
}
if ($roles->isEmpty()) {
return false;
}
return true;
}

public function canAccessPanel(Panel $panel): bool
{
$panelGetId = $panel->getId();

return match($panelGetId) {
'admin' => auth()->user()->hasRole(['admin']),
'company' => auth()->user()->hasRole(['owner']),
'client' => auth()->user()->hasRole(['client']),
};
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}

public function hasRole($userRoles)
{
if (is_array($userRoles)) {
$roles = $this->roles->whereIn('name', $userRoles);
} else {
$roles = $this->roles->where('name', $userRoles);
}
if ($roles->isEmpty()) {
return false;
}
return true;
}

public function canAccessPanel(Panel $panel): bool
{
$panelGetId = $panel->getId();

return match($panelGetId) {
'admin' => auth()->user()->hasRole(['admin']),
'company' => auth()->user()->hasRole(['owner']),
'client' => auth()->user()->hasRole(['client']),
};
}
This is giving an error saying undefined method 'hasRole'
55 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
By the way, I missed a step... https://filamentphp.com/docs/3.x/panels/tenancy#customizing-the-ownership-relationship-name This is mainly for things to belong to a company though, but I think this will let me get rid of updating the company_id through the create method in the model (when creating a new record) Don't miss this step like I did haha - I'll let you know if it fixes my issues 🙂
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
I just thought of a different way to do it as well, where I have just 1 panel for Company. Within this Panel, I would only allow resources for certain Roles For instance, If they have Owner and Client Role, they would see all Owner and Client resources If they only had Client role, they would use the same Panel, but would only see Client resources - that may be the easier approach so they don't have to switch paths just to access a different Role. I just have to think more
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
And yes, they would have the same Role in all of them - no way to separate - so I'll keep that in mind with my designing as well
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
Okay thank you. That's what I thought, I can't have Permissions for each Role. I just have to make it Role only and design each Panel based on that Role - and that's probably the easiest simplest idea until a potential package/etc is introduced I appreciate the help forsure, and the time you have put into helping me!
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
All good, thank you for the dedication!
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
Alright I appreciate it 🙂 I figure worse case, it will just show all companies available to them, and whatever panel they are in will be the "role". Like if they are in a Company Panel, they can only do Company Role type stuff, and Client Panel can only do Client Role stuff... And the role itself (in role_user table) would just be to allow access to those Panels in general, but wouldn't control much else past this I suppose I would also have to make sure each Panel is only allowed to do specific things for the specific Role, but the problem with this is that I definitely wouldn't be able to use any permissions to narrow it down even further (where someone can make a new Role and assign it certain Permissions like allowing someone to add/edit a User within the Company while restricting other Users from doing so) So yeah if you figure out an idea let me know - I only ask because I couldn't find it on my own 😦 and sadly a lot of the examples are for version 2 which haven't worked on version 3 :/
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
But I need a way to specify each company for each row in role_user pivot table, so when a user switches companies, they have their specific role For instance, lets say [email protected] signs up as a Owner to their own company (they create a company) Then [email protected] also gets added as a Client to another company If they switch companies, I wont have a way to make sure they have the specific Client or Owner permission without setting the company_id in role_user table... but filament doesn't insert this extra column value automatically Hopefully this makes sense. I understand if you're unable to help with this as well
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
How to set company_id in role_user table
Yes that's correct. And yes that works perfectly in filament, everything is separated like it should be. The problem is roles & permissions, I want to allow a company Owner to create new users with things like Client, Manager, Breeder, etc... This is where filament fails for now, so I made my own Role system that uses role_user table to decide what Role they are, and based on that Role (like Owner, Manager, Breeder, Client), they will have certain Panels and certain capabilities (like adding/deleting other users, adding/deleting records, and more)
16 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
Hide column in table conditionally
Thank you so much, you're the best
11 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
Hide column in table conditionally
It works! Just forgot a ; at the end of $record->expected
11 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
Hide column in table conditionally
Oh! Okay I'll try that out, I didn't even know that was possible
11 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/16/2023 in #💡filament
Hide column in table conditionally
Yeah it would be row specific, not the whole column - my fault
11 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/15/2023 in #💡filament
Pivot table issue
Nevermind, I'm going to get rid of this pivot situation and switch it back to just 1 company ID for each record of this litters table For anyone else curious, looks like it has to be like this: https://stackoverflow.com/questions/73505050/laravel-many-to-many-relationship-with-pivot For me, that's just too involved right now haha Thank you!
3 replies
TLCTuto's Laravel Corner
Created by JamesTechDude on 8/15/2023 in #💡filament
Pivot table issue
It looks like I have to use something like this, but it's not too clear on how to properly do this... https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-a-belongstomany-eloquent-relationship
3 replies