nwalty
nwalty
FFilament
Created by nwalty on 3/12/2024 in #❓┊help
Best way to determine which resource a select component is currently being rendered on
What would be the best way to determine what resource a shared select field is currently on to gather the context and update the available options? I have tried using RelationManager $livewire->getOwnerRecord() but this throws an error if I access the Resource directly. I have also played a little bit with the Livewire component and form component instances but wasn't getting very far with that and wasn't entirely sure that was the best route to go with this. EntityRoleResource shares its form on SchoolResource->RolesRelationManager and ProgramResource->RolesRelationManager. EntityRoleResource has a Select::make(role_id) where the role options would be dependent on the entity context (ie School or Program when rendered in their respective relation managers). Edit: EntityRoleResource should have all available options when being worked with directly.
4 replies
FFilament
Created by nwalty on 11/21/2023 in #❓┊help
Dynamic Fields Based on Select Option Issue
I am encountering a issue with dynamic form fields. When attempting to use any form layout components within the match function the dynamic select jumps to null and nothing else happens (continues to display the default form fields). I haven't received any errors on console for this issue. When not including any layout components the form fields load as expected.
Forms\Components\Select::make('type')
->label('Contest Type')
->options([
'Contest' => 'Contest (single game)',
'Tournament' => 'Tournament',
])
->default('Contest')
->live()
->afterStateUpdated(fn (Forms\Components\Select $component) =>
$component->getContainer()
->getComponent('dynamicTypeFields')
->getChildComponentContainer()
->fill()
)
->visibleOn('create'),
Forms\Components\Grid::make(2)
->schema(fn (Get $get): array =>
match ($get('type')) {
'Tournament' => [
Forms\Components\Fieldset::make() //Remove this and it works
->schema([
Forms\Components\TextInput::make('name')
->required(),
])
],
default => [
Forms\Components\DateTimePicker::make('start_at')
->label('Date'),
],
}
)
->key('dynamicTypeFields'),
Forms\Components\Select::make('type')
->label('Contest Type')
->options([
'Contest' => 'Contest (single game)',
'Tournament' => 'Tournament',
])
->default('Contest')
->live()
->afterStateUpdated(fn (Forms\Components\Select $component) =>
$component->getContainer()
->getComponent('dynamicTypeFields')
->getChildComponentContainer()
->fill()
)
->visibleOn('create'),
Forms\Components\Grid::make(2)
->schema(fn (Get $get): array =>
match ($get('type')) {
'Tournament' => [
Forms\Components\Fieldset::make() //Remove this and it works
->schema([
Forms\Components\TextInput::make('name')
->required(),
])
],
default => [
Forms\Components\DateTimePicker::make('start_at')
->label('Date'),
],
}
)
->key('dynamicTypeFields'),
4 replies
FFilament
Created by nwalty on 9/14/2023 in #❓┊help
FileUpload to AWS S3 ACL error
Morning all, I am working on an image upload to s3. Temp file gets created correctly but when attempting to save the file I receive the following error code from S3: "AccessControlListNotSupported". This is technically correct as I am enforcing Bucket Policy. I am using Cloudfront as a passthrough if that makes a difference. Has anyone encountered this? is there a setting somewhere that I can change? I am sure I am missing something obvious.
2 replies
FFilament
Created by nwalty on 6/21/2023 in #❓┊help
FileUpload Image with morphOne relationship
I am trying to get the FileUpload field to work with all of the image morphOne relationships I have in my program. An example of one of the relationships is included below. FileUpload is being called on SchoolResource.php. School.php is related to ProgramOperator.php via the 'entity' relationship. I am guessing I am missing something painfully obvious somewhere. EntityImage.php
Class EntityImage extends Model {
protected $table = 'images';

protected static $storageBucket = 'entities';

protected static $sizes = array('800x600', '500x400', '200x150');
protected static $resize_method = 'resize';

public function __construct()
{

}

public function imageable(): MorphTo
{
return $this->morphTo();
}

public function getUrlAttribute()
{
return Storage::url('uploads/' . $this->bucket . '/' . $this->filename);
}
}
Class EntityImage extends Model {
protected $table = 'images';

protected static $storageBucket = 'entities';

protected static $sizes = array('800x600', '500x400', '200x150');
protected static $resize_method = 'resize';

public function __construct()
{

}

public function imageable(): MorphTo
{
return $this->morphTo();
}

public function getUrlAttribute()
{
return Storage::url('uploads/' . $this->bucket . '/' . $this->filename);
}
}
ProgramLogo.php
class ProgramLogo extends EntityImage {

protected static $storageBucket = 'programs';
protected static $sizes = array('800x800', '400x400', '128x128', '64x64', '32x32', '16x16');

}
class ProgramLogo extends EntityImage {

protected static $storageBucket = 'programs';
protected static $sizes = array('800x800', '400x400', '128x128', '64x64', '32x32', '16x16');

}
ProgramOperator.php
class ProgramOperator extends Model
{
use SoftDeletes;

public $timestamps = true;

protected $table = 'program_operators';

protected $fillable = array('name', 'is_active', 'mascot_name', 'color1_name', 'color2_name', 'color3_name', 'song_name', 'song_theme', 'song_lyrics');
public function entity()
{
return $this->morphTo();
}

public function image()
{
return $this->morphOne(ProgramLogo::class, 'imageable');
}

}
class ProgramOperator extends Model
{
use SoftDeletes;

public $timestamps = true;

protected $table = 'program_operators';

protected $fillable = array('name', 'is_active', 'mascot_name', 'color1_name', 'color2_name', 'color3_name', 'song_name', 'song_theme', 'song_lyrics');
public function entity()
{
return $this->morphTo();
}

public function image()
{
return $this->morphOne(ProgramLogo::class, 'imageable');
}

}
3 replies
FFilament
Created by nwalty on 4/27/2023 in #❓┊help
mutateFormDataBeforeCreate on wizard
I am trying to add a "from_user_id" to $data via mutateFormDataBeforeCreate(). I can dump $data before the creation and it shows "from_user_id" in the array with the correct user id. When I repeat without the dump, the user id is not saved to the DB.
7 replies
FFilament
Created by nwalty on 4/14/2023 in #❓┊help
RelationManager error when using custom create
I am getting a SQL general error stating that field 'is_approved' doesn't have a default value (which is correct, it doesn't). I am guessing I am missing something obvious in the code below when customizing my data prior to saving.
->headerActions([
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$role = Role::find($data['role_id']);

if ($role->entity_type == 'Program') {
$data['entity_id'] = $data['program_id'];
}

$data['entity_type'] = $role->entity_type;

$data['name'] = $role->name;

$data['is_approved'] = 0;

if(request()->user()->hasPermissionOnAny('StateAssociation', 'manage-users')){
$data['is_approved'] = 1;
}

return $data;
})

// Removed unrelated code here.

->using(function (RelationManager $livewire, array $data) {

return $livewire->getRelationship()->create($data);

})
->hidden(fn ( $livewire): string => $livewire instanceof ViewUser),

])
->headerActions([
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$role = Role::find($data['role_id']);

if ($role->entity_type == 'Program') {
$data['entity_id'] = $data['program_id'];
}

$data['entity_type'] = $role->entity_type;

$data['name'] = $role->name;

$data['is_approved'] = 0;

if(request()->user()->hasPermissionOnAny('StateAssociation', 'manage-users')){
$data['is_approved'] = 1;
}

return $data;
})

// Removed unrelated code here.

->using(function (RelationManager $livewire, array $data) {

return $livewire->getRelationship()->create($data);

})
->hidden(fn ( $livewire): string => $livewire instanceof ViewUser),

])
2 replies