remove the single DeleteAction from specific records
remove the single DeleteAction from specific rows, for example, users with is_admin = 1 so admin users can't be deleted.
tried to use this
->before(function (DeleteAction $action) {
if (! $this->record->is_admin = 1) {
but get that error about ' $this '
i'm very new π
17 Replies
->hidden(fn (User $record): bool => $user->is_admin)
thanks @Dan Harrin
I've tried to add it as bellow
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()->hidden(fn (User $record): bool => $user->is_admin)
])
but when i load the page I get
Attempt to read property "is_admin" on null
weird, can you share the full code
because im 99% sure the code you just pasted is not the code you are actually using
since if it was the code you were using, the error would be different. since User is not a nullable type
We need more information to help you debug your problem. Please click on the top left 'SHARE' button of the error page you're seeing and share the link with us.
Flare
Attempt to read property "is_admin" on null - The error occurred at http://baseapp.test/tenant_manager/users
sorry
ive just realised my stupid mistake
->hidden(fn (User $record): bool => $record->is_admin)
π€¦ββοΈactually i though about it and got an error also , https://flareapp.io/share/qm1dwOp5
Flare
Typed property App\Models\User::$is_admin must not be accessed before initialization - The error occurred at http://baseapp.test/tenant_manager/users
is is_admin not a column in your db table?
why is it a property
its a column
can you send your model
ok
$table->boolean('is_admin')->after('name')->default(0);
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
class User extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable, HasRoles, SoftDeletes, HasUuids;
/
* @var int|mixed
*/
public mixed $is_admin;
/
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'is_admin',
'email',
'password',
];
/
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function canAccessFilament(): bool { return str_ends_with($this->email, '@admin.com'); } }
public function canAccessFilament(): bool { return str_ends_with($this->email, '@admin.com'); } }
why is it a property lol
you dont need it if its a column?
sorry im' not geting it π¦
you dont need
public mixed $is_admin;
its useless in eloquent and breaks itoh
got it
Thanks for your time , I'm not a developer i'm just someone how google things and try to make them work π
haha ok