Jamie Cee
Jamie Cee
FFilament
Created by Matthew on 4/2/2024 in #❓┊help
Deferring loading
Apologies for jumping to an old conversation. WIth this, it has improved the speed of my tables loading, but when I search the table for specific records - the table looks like its just froze until the data loads. Do you know of any way to work around this?
6 replies
FFilament
Created by Jamie Cee on 11/19/2024 in #❓┊help
table layout styling
No description
4 replies
FFilament
Created by Jamie Cee on 11/19/2024 in #❓┊help
table layout styling
It should only stack the name and username fields? Also all toggleable columns dont seem to have its functionality when using Stack, Split etc
4 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
I Finally found it. So basically where im creating the temp users, I have to cast the uuid as a string when creating
$user->id = (string) Str::uuid();
$user->id = (string) Str::uuid();
Else it was detecting as a LazyLoadFromUuid or some named object
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
WIll do. Thank you
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
The checkPermissionTo() came with the generation command. Apologies, im also using the https://github.com/althinect/filament-spatie-roles-permissions repo
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
Ill try replicate and give it a go
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
Sadly its a work one, so NDA. I can try mimic as much of this as possible to remove redacted information to share. What particularly would you be looking for?
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
Im not actually wiping the database currently during these tests, so those permissions do already exist in the db.
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
But even then, its Super Admin im adding, does that not cover all permissions?
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
I've just tried adding ->givePermissionTo() on the user, but still getting the same Illegal offset type error. Im just so confused
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('User.view-any') || $user->canManageAnyOrganisations();
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, User $model): bool
{
return $user->checkPermissionTo('User.view');
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('User.create');
}
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('User.view-any') || $user->canManageAnyOrganisations();
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, User $model): bool
{
return $user->checkPermissionTo('User.view');
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('User.create');
}
Along the lines of this, but I've even tested by just returning true in every function, same outcome
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
Done a dd in the TestCase, I can see the role definitely exists, and returns true if I check the user having the role
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
I have this in my TestCase setup flow
protected function createUserRecord(): User
{
/* Allow us to use faker */
$faker = \Faker\Factory::create('en_GB');

/* Create a user - no idea why the factory method would not work */
$user = new User();
$user->id = Str::uuid();
$user->name = $faker->name();
$user->email = $faker->unique()->userName() . \Illuminate\Support\Str::random(12) . '@example.com';
$user->email_verified_at = null;
$user->password = Hash::make('Password1!'); //password
$user->save();

if (!Role::where('name', RoleConstants::SUPER_ADMIN)->first()) {
Role::create(['name' => RoleConstants::SUPER_ADMIN]);
}

/* Give user Super Admin */
$user->assignRole(RoleConstants::SUPER_ADMIN);

return $user;
}
protected function createUserRecord(): User
{
/* Allow us to use faker */
$faker = \Faker\Factory::create('en_GB');

/* Create a user - no idea why the factory method would not work */
$user = new User();
$user->id = Str::uuid();
$user->name = $faker->name();
$user->email = $faker->unique()->userName() . \Illuminate\Support\Str::random(12) . '@example.com';
$user->email_verified_at = null;
$user->password = Hash::make('Password1!'); //password
$user->save();

if (!Role::where('name', RoleConstants::SUPER_ADMIN)->first()) {
Role::create(['name' => RoleConstants::SUPER_ADMIN]);
}

/* Give user Super Admin */
$user->assignRole(RoleConstants::SUPER_ADMIN);

return $user;
}
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
THese tests used to work, until I implemented the spatie perrmissions plugin
27 replies
FFilament
Created by Jamie Cee on 11/18/2024 in #❓┊help
illegal offset type in tests
And the page its referencing
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;

/**
* Redirect after save
*
* @return string
*/
protected function getRedirectUrl(): string
{
return $this->previousUrl ?? $this->getResource()::getUrl('index');
}

/**
* @param array<string, mixed> $data
*/
protected function handleRecordCreation(array $data): Model
{
/* Define the password so we can send in the instructions email */
$password = $data['password'];

/* Hash the password thats stored in the db */
$data['password'] = Hash::make($password);

/* Create the user */
$user = parent::handleRecordCreation($data);

/* Send the login instructions */
if (
array_key_exists('email_welcome_instructions', $data)
&& $data['email_welcome_instructions'] === true
&& !$user->sendLoginInstructions(password: $password)
) {
\Filament\Notifications\Notification::make()
->title('There was an error sending out instructions')
->danger()
->send();
}

return $user;
}
}
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;

/**
* Redirect after save
*
* @return string
*/
protected function getRedirectUrl(): string
{
return $this->previousUrl ?? $this->getResource()::getUrl('index');
}

/**
* @param array<string, mixed> $data
*/
protected function handleRecordCreation(array $data): Model
{
/* Define the password so we can send in the instructions email */
$password = $data['password'];

/* Hash the password thats stored in the db */
$data['password'] = Hash::make($password);

/* Create the user */
$user = parent::handleRecordCreation($data);

/* Send the login instructions */
if (
array_key_exists('email_welcome_instructions', $data)
&& $data['email_welcome_instructions'] === true
&& !$user->sendLoginInstructions(password: $password)
) {
\Filament\Notifications\Notification::make()
->title('There was an error sending out instructions')
->danger()
->send();
}

return $user;
}
}
27 replies
FFilament
Created by Jamie Cee on 11/8/2024 in #❓┊help
slow performance and 500 errors with large data
However, next thing I've found is actions. Specifically edit and delete which have some model condition checks. These seem to add 200ms onto the call, is there anyway to optimise these, or is this the best way?
Tables\Actions\EditAction::make()
->tooltip('Edit User')
->color('warning')
->hidden(fn(Model $record) => $record->trashed())
->label('Edit User'),
Tables\Actions\DeleteAction::make()
->tooltip('Delete User')
->hidden(function (Model $record) use ($user): bool {
if ($record->getKey() === $user->getKey() || $record->trashed()) {
return true;
}

return false;
})
->label('Delete User'),

Tables\Actions\EditAction::make()
->tooltip('Edit User')
->color('warning')
->hidden(fn(Model $record) => $record->trashed())
->label('Edit User'),
Tables\Actions\DeleteAction::make()
->tooltip('Delete User')
->hidden(function (Model $record) use ($user): bool {
if ($record->getKey() === $user->getKey() || $record->trashed()) {
return true;
}

return false;
})
->label('Delete User'),

56 replies
FFilament
Created by Jamie Cee on 11/8/2024 in #❓┊help
slow performance and 500 errors with large data
Oh wait, I've read it wrong still...
56 replies
FFilament
Created by Jamie Cee on 11/8/2024 in #❓┊help
slow performance and 500 errors with large data
Got to 21k inserts, then memory limit exhausted again 🤣 Ill just re-run several times still
56 replies
FFilament
Created by Jamie Cee on 11/8/2024 in #❓┊help
slow performance and 500 errors with large data
Would you still run it in a for loop typically?
56 replies