I can't show all records!

Hello, I have a model where I manage all the system permissions but I cannot show all the records, in the case of this model it is not necessary that it belongs to a tenant or there is an ownershipRelationship, however the configuration requires me to have an owner How can I avoid this? I had my model like this:
<?php

namespace App\Models;

use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;

class Permission extends Model
{
use HasFactory;

protected $fillable = [
'name',
];

public function users(): BelongsToMany
{
return $this->belongsToMany(User::class);
}

public function owner(): HasMany
{
//return $this->hasMany(Permission::class, 'id');
return $this->hasMany(Permission::class, 'id')->where('id', '<>', 0);
}
}
<?php

namespace App\Models;

use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;

class Permission extends Model
{
use HasFactory;

protected $fillable = [
'name',
];

public function users(): BelongsToMany
{
return $this->belongsToMany(User::class);
}

public function owner(): HasMany
{
//return $this->hasMany(Permission::class, 'id');
return $this->hasMany(Permission::class, 'id')->where('id', '<>', 0);
}
}
later i try this:
<?php

namespace App\Models;

use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Permission extends Model
{
use HasFactory;

protected $fillable = [
'name',
];

public function users(): BelongsToMany
{
return $this->belongsToMany(User::class);
}

public function owner()
{
//Filament::getTenant()->id;
//return $this->hasMany(Permission::class, 'id');
$permissions = Permission::where('id', '>=', 1)->get();
//dd($permissions);
return $permissions;
//return $this->hasMany(Permission::class, 'id')->where('id', '>=', Filament::getTenant()->id);
}
}
<?php

namespace App\Models;

use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Permission extends Model
{
use HasFactory;

protected $fillable = [
'name',
];

public function users(): BelongsToMany
{
return $this->belongsToMany(User::class);
}

public function owner()
{
//Filament::getTenant()->id;
//return $this->hasMany(Permission::class, 'id');
$permissions = Permission::where('id', '>=', 1)->get();
//dd($permissions);
return $permissions;
//return $this->hasMany(Permission::class, 'id')->where('id', '>=', Filament::getTenant()->id);
}
}
No description
No description
4 Replies
TranceCode
TranceCodeOP11mo ago
and i have my Panel like this:
<?php

namespace App\Providers\Filament;

use App\Models\Company;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class CompanyPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->id('company')
->path('gym')
->colors([
'danger' => Color::rgb('rgb(255,0,0)'),
'gray' => Color::Gray,
'info' => Color::Green,
'primary' => Color::Violet,
'success' => Color::Lime,
'warning' => Color::rgb('rgb(255,69,0)'),
'edit' => Color::Blue,
])
->authGuard('company')
->profile()
->login()
->passwordReset()
->authPasswordBroker('companies')
->maxContentWidth('full')
->sidebarCollapsibleOnDesktop()
->discoverResources(in: app_path('Filament/Company/Resources'), for: 'App\\Filament\\Company\\Resources')
->discoverPages(in: app_path('Filament/Company/Pages'), for:
<?php

namespace App\Providers\Filament;

use App\Models\Company;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class CompanyPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->id('company')
->path('gym')
->colors([
'danger' => Color::rgb('rgb(255,0,0)'),
'gray' => Color::Gray,
'info' => Color::Green,
'primary' => Color::Violet,
'success' => Color::Lime,
'warning' => Color::rgb('rgb(255,69,0)'),
'edit' => Color::Blue,
])
->authGuard('company')
->profile()
->login()
->passwordReset()
->authPasswordBroker('companies')
->maxContentWidth('full')
->sidebarCollapsibleOnDesktop()
->discoverResources(in: app_path('Filament/Company/Resources'), for: 'App\\Filament\\Company\\Resources')
->discoverPages(in: app_path('Filament/Company/Pages'), for:
'App\\Filament\\Company\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Company/Widgets'), for: 'App\\Filament\\Company\\Widgets')
->widgets([
//
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
])
->tenant(Company::class, slugAttribute: 'slug', ownershipRelationship: 'owner');
}
}
'App\\Filament\\Company\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Company/Widgets'), for: 'App\\Filament\\Company\\Widgets')
->widgets([
//
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
])
->tenant(Company::class, slugAttribute: 'slug', ownershipRelationship: 'owner');
}
}
krekas
krekas11mo ago
how are you showing permissions in the resource? how's the query looks?
TranceCode
TranceCodeOP11mo ago
here is my resource @krekas
<?php

namespace App\Filament\Company\Resources;

use App\Filament\Company\Resources\PermissionResource\Pages;
use App\Models\Permission;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class PermissionResource extends Resource
{
protected static ?string $model = Permission::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

protected static ?string $navigationGroup = 'Seguridad y Administracion';

protected static ?int $navigationSort = 31;

public static function getPluralLabel(): ?string
{
return ("Permisos");
}

public static function getLabel(): ?string
{
return ('Permiso');
}

public static function form(Form $form): Form
{
return $form
->schema([
//
Forms\Components\TextInput::make('name')
->label('Nombre')
->required()
->autofocus()
->maxLength(200),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('name')
->label('Nombre')
->searchable()
->sortable(),
])
->filters([
])
->actions([
])
->bulkActions([
])
->emptyStateActions([
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListPermissions::route('/'),
//'create' => Pages\CreatePermission::route('/create'),
//'edit' => Pages\EditPermission::route('/{record}/edit'),
];
}
}
<?php

namespace App\Filament\Company\Resources;

use App\Filament\Company\Resources\PermissionResource\Pages;
use App\Models\Permission;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class PermissionResource extends Resource
{
protected static ?string $model = Permission::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

protected static ?string $navigationGroup = 'Seguridad y Administracion';

protected static ?int $navigationSort = 31;

public static function getPluralLabel(): ?string
{
return ("Permisos");
}

public static function getLabel(): ?string
{
return ('Permiso');
}

public static function form(Form $form): Form
{
return $form
->schema([
//
Forms\Components\TextInput::make('name')
->label('Nombre')
->required()
->autofocus()
->maxLength(200),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('name')
->label('Nombre')
->searchable()
->sortable(),
])
->filters([
])
->actions([
])
->bulkActions([
])
->emptyStateActions([
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListPermissions::route('/'),
//'create' => Pages\CreatePermission::route('/create'),
//'edit' => Pages\EditPermission::route('/{record}/edit'),
];
}
}
krekas
krekas11mo ago
You didn't show how the query looks bu why you have that where added to the relation?
Want results from more Discord servers?
Add your server