Table Data Visibility
I created a dispatch system in Laravel Filament where users can assign Workorders to Vendors. I get all my Vendors from my User model which has a 'role' of 'Vendor'. I've also set up a relationship between my User and Workorder model.
Currently, all Workorders can be seen by the Vendors even if that WO is not assigned to them. I want to add a function where 'Vendors' can only see the Workorder that was assigned to them.
Here's what I did which is throwing me an error of: Cannot use "::class" on value of type null
public static function table(Table $table): Table
{
return $table
->query(function (Builder $query) {
// Base query that fetches all work orders
$baseQuery = $query->select('*')->from('workorders');
// If user is a Vendor, modify the base query to only include their work orders
if (Auth::user()->hasRole('Vendor')) {
return $baseQuery->where('user_id', Auth::id());
}
// Otherwise, return the base query
return $baseQuery;
})
Currently, all Workorders can be seen by the Vendors even if that WO is not assigned to them. I want to add a function where 'Vendors' can only see the Workorder that was assigned to them.
Here's what I did which is throwing me an error of: Cannot use "::class" on value of type null
public static function table(Table $table): Table
{
return $table
->query(function (Builder $query) {
// Base query that fetches all work orders
$baseQuery = $query->select('*')->from('workorders');
// If user is a Vendor, modify the base query to only include their work orders
if (Auth::user()->hasRole('Vendor')) {
return $baseQuery->where('user_id', Auth::id());
}
// Otherwise, return the base query
return $baseQuery;
})