MrHex
MrHex
FFilament
Created by MrHex on 12/25/2023 in #❓┊help
Many to many relations with extra pivot field using Repeaters
Hi, I have a User model and a Course model there is also a course_user table with user_id, course_id and type fields. Relation from the Course model is:
public function users()
{
return $this->belongsToMany(User::class, 'course_user')
->withPivot('type')
->withTimestamps();
}
public function users()
{
return $this->belongsToMany(User::class, 'course_user')
->withPivot('type')
->withTimestamps();
}
Now i want to use this relation in a Repeater but the fields does not fill correctly.
5 replies
FFilament
Created by MrHex on 9/7/2023 in #❓┊help
Issues with Registering Panels in FilamentPHP: Seeking Help and Insights
Hello everyone, I'm currently working on a package that adds modular functionality to Filament and allows loading panels from custom paths. However, I've encountered an issue. When I attempt to register a new panel in Filament, it doesn't seem to have any effect. There are no errors or warnings, but no panels are being displayed. I tried loading my ServiceProvider before the Filament ServiceProvider or registering it using AppServiceProvider, and it works perfectly. However, when it's loaded using Laravel's auto-discovery feature, it doesn't work. Any insights or suggestions on how to resolve this would be greatly appreciated.
1 replies
FFilament
Created by MrHex on 4/27/2023 in #❓┊help
Image upload in relations
I Have a User model with a PersonalInfo relation:
class User extends Model
{
/**
* Get the user PI
*
* @return HasOne
*/
public function personalInfo(): HasOne
{
return $this->hasOne(PersonalInfo::class, 'user_id', 'id');
}
}
class User extends Model
{
/**
* Get the user PI
*
* @return HasOne
*/
public function personalInfo(): HasOne
{
return $this->hasOne(PersonalInfo::class, 'user_id', 'id');
}
}
in the PersonalInfo we have an avatar_id column that references to File model:
class PersonalInfo extends Model
{
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'user_id',
'first_name',
'last_name',
'avatar_id', // here is the column
];

/**
* Get the avatar file
*
* @return BelongsTo
*/
public function avatar(): BelongsTo
{
return $this->belongsTo(File::class, 'avatar_id', 'id');
}
}
class PersonalInfo extends Model
{
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'user_id',
'first_name',
'last_name',
'avatar_id', // here is the column
];

/**
* Get the avatar file
*
* @return BelongsTo
*/
public function avatar(): BelongsTo
{
return $this->belongsTo(File::class, 'avatar_id', 'id');
}
}
now i just made a PersonalInfoRelationManager to manage the relation from the UserResource and used the FileUpload form input like this:
FileUpload::make('avatar')
->image()
->demonLabel()
->columnSpan('full')
->saveUploadedFileUsing(
function ($file, callable $get, callable $set)
{
$dir = 'public/static/avatar/' . md5($get('id'));
$path = $file->storePublicly($dir);
$path = str_replace('public/static/', 'static/', $path);

$avatar = file_repo()->create(
[
'uploader_id' => auth()->id(),
'disk' => 'public',
'name' => $file->getClientOriginalName(),
'extension' => $file->getClientOriginalExtension(),
'path' => $path,
'alt' => '',
],
);

$set('avatar_id', $avatar->id);
},
)
->reactive()
FileUpload::make('avatar')
->image()
->demonLabel()
->columnSpan('full')
->saveUploadedFileUsing(
function ($file, callable $get, callable $set)
{
$dir = 'public/static/avatar/' . md5($get('id'));
$path = $file->storePublicly($dir);
$path = str_replace('public/static/', 'static/', $path);

$avatar = file_repo()->create(
[
'uploader_id' => auth()->id(),
'disk' => 'public',
'name' => $file->getClientOriginalName(),
'extension' => $file->getClientOriginalExtension(),
'path' => $path,
'alt' => '',
],
);

$set('avatar_id', $avatar->id);
},
)
->reactive()
the upload process is fine but when i re-open to modal, image doesn't shown to me... 😦 How can I fix this issue?
38 replies