N1XN
N1XN
FFilament
Created by N1XN on 11/6/2023 in #❓┊help
Column headers using Split
No description
4 replies
FFilament
Created by N1XN on 11/1/2023 in #❓┊help
Display widget inside modal
I would like to display a widget inside a modal after a action is clicked. Just would like to know if it is possible without creating a custom view for that, as maybe somebody already solved that case.
2 replies
FFilament
Created by N1XN on 10/21/2023 in #❓┊help
Save prefix values
How can I save the TextInput including the prefix? I know that I can extend the handleRecordCreation method but then I would have the string prefix saved to DB (this is actually wanted and needed) but showing or editing the record would have the prefix and the prefixed string - basically double prefixed.
Select::make('group_id')
->label('Group')
->relationship('group', 'code')
->reactive()
->required(),

TextInput::make('code')
->label('Party code')
->prefix(fn (Closure $get) => $get('group_id') ? Party::find($get('group_id'))->code.'-' : '')
->required(),
Select::make('group_id')
->label('Group')
->relationship('group', 'code')
->reactive()
->required(),

TextInput::make('code')
->label('Party code')
->prefix(fn (Closure $get) => $get('group_id') ? Party::find($get('group_id'))->code.'-' : '')
->required(),
4 replies
FFilament
Created by N1XN on 9/30/2023 in #❓┊help
Disable auth (cache)
php artisan route:cache "reanables" disabled routes. - setting login to null in /config/filament.php - permanently redirect to my auth in /routes/auth.php https://discord.com/channels/883083792112300104/1143739713925152929
4 replies
FFilament
Created by N1XN on 9/29/2023 in #❓┊help
S3 visibility
I am uploading files via spatie media library to S3 (digital ocean spaces). Unfortunately setting the ->visibility('public') does not get recognized. Am I doing something wrong, or am I missing something here?
SpatieMediaLibraryFileUpload::make('images')
->label('Bilder')
->acceptedFileTypes(['image/jpg', 'image/jpeg', 'image/png'])
->collection('images')
->multiple()
->visibility('public') // doing nothing...
->required(),
SpatieMediaLibraryFileUpload::make('images')
->label('Bilder')
->acceptedFileTypes(['image/jpg', 'image/jpeg', 'image/png'])
->collection('images')
->multiple()
->visibility('public') // doing nothing...
->required(),
16 replies
FFilament
Created by N1XN on 9/29/2023 in #❓┊help
Unable to retrieve the mime_type for file at location: livewire-tmp/kHGEXYiSJSh3w2av6KCn8cYKvfexf6-m
Trying to upload files via SpatieMediaLibraryFileUpload but results in error: config/filesystem.php
'minio' => [
'driver' => 's3',
'endpoint' => env('MINIO_ENDPOINT'),
'key' => env('MINIO_KEY'),
'secret' => env('MINIO_SECRET'),
'region' => env('MINIO_DEFAULT_REGION'),
'bucket' => env('MINIO_BUCKET'),
'use_path_style_endpoint' => true,
'throw' => true,
],
'minio' => [
'driver' => 's3',
'endpoint' => env('MINIO_ENDPOINT'),
'key' => env('MINIO_KEY'),
'secret' => env('MINIO_SECRET'),
'region' => env('MINIO_DEFAULT_REGION'),
'bucket' => env('MINIO_BUCKET'),
'use_path_style_endpoint' => true,
'throw' => true,
],
Inside filament form
SpatieMediaLibraryFileUpload::make('images')
->label('Images')
->image()
->collection('images')
->multiple()
->imageResizeMode('cover')
->imageCropAspectRatio('16:9')
->imageResizeTargetWidth('1920')
->imageResizeTargetHeight('1080')
->enableReordering()
->required(),
SpatieMediaLibraryFileUpload::make('images')
->label('Images')
->image()
->collection('images')
->multiple()
->imageResizeMode('cover')
->imageCropAspectRatio('16:9')
->imageResizeTargetWidth('1920')
->imageResizeTargetHeight('1080')
->enableReordering()
->required(),
The images get uploaded to minio but to livewire-tmp
4 replies
FFilament
Created by N1XN on 9/20/2023 in #❓┊help
Image carousel/preview
I am searching for a solution where I can display related images from a table. Maybe opening a modal and display a carousel something in that matter.. Does anybody know if something like that already exist?
2 replies
FFilament
Created by N1XN on 8/28/2023 in #❓┊help
Access nested sum
How can I display the dose_count inside a TextColumn?
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->with(['patients' => function ($query) {
$query->withSum('latestPatientProtocol', 'dose_count');
}]);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->with(['patients' => function ($query) {
$query->withSum('latestPatientProtocol', 'dose_count');
}]);
}
9 replies
FFilament
Created by N1XN on 8/27/2023 in #❓┊help
RelationManager attempts to lazy load relations
I have created an Attribute to display a range, which combines min and max BelongsTo Relations, but I get the enabled strictMode error thrown. Attempted to lazy load [minDose] on model [App\Models\PatientMedication] but lazy loading is disabled. Is there a way how I can manually load the needed relations via TextColumn API?
// MedicationDoseRelationManager
// ...
TextColumn::make('medicationDoseRange')
->label('Dose'),
// ...
// MedicationDoseRelationManager
// ...
TextColumn::make('medicationDoseRange')
->label('Dose'),
// ...
class PatientMedication extends Model
{
public function minDose(): BelongsTo
{
return $this->belongsTo(Dose::class, 'min_dose_id');
}

public function maxDose(): BelongsTo
{
return $this->belongsTo(Dose::class, 'max_dose_id');
}

protected function medicationDoseRange(): Attribute
{
return Attribute::make(
get: function () {
$consolidatedValue = $this->minDose->name === $this->maxDose->name; // Error get trown

return $consolidatedValue
? $this->minDose->name
: $this->minDose->name.' - '.$this->maxDose->name;
}
);
}
}
class PatientMedication extends Model
{
public function minDose(): BelongsTo
{
return $this->belongsTo(Dose::class, 'min_dose_id');
}

public function maxDose(): BelongsTo
{
return $this->belongsTo(Dose::class, 'max_dose_id');
}

protected function medicationDoseRange(): Attribute
{
return Attribute::make(
get: function () {
$consolidatedValue = $this->minDose->name === $this->maxDose->name; // Error get trown

return $consolidatedValue
? $this->minDose->name
: $this->minDose->name.' - '.$this->maxDose->name;
}
);
}
}
3 replies
FFilament
Created by N1XN on 8/26/2023 in #❓┊help
Sum latest HasThroughMany
How can I sum the latestPatientProtcols.hours within a DoctorResource ? Doctor -> hasMany Patient -> hasMany -> PatientProtocol
TextColumn::make('latest_patient_protocols_sum_hours')
->sum('latestPatientProtocols', 'cubic_value'),
TextColumn::make('latest_patient_protocols_sum_hours')
->sum('latestPatientProtocols', 'cubic_value'),
<?php

class Doctor extends BaseModel
{
public function patients(): HasMany
{
return $this->hasMany(Patient::class);
}

public function latestPatientProtocols(): Collection
{
return $this->patients->map(fn (Patient $patients) => $patients->latestPatientProtocols)->filter();
}
<?php

class Doctor extends BaseModel
{
public function patients(): HasMany
{
return $this->hasMany(Patient::class);
}

public function latestPatientProtocols(): Collection
{
return $this->patients->map(fn (Patient $patients) => $patients->latestPatientProtocols)->filter();
}
<?php

namespace App\Models;

class Patient extends BaseModel
{
public function doctor(): BelongsTo
{
return $this->belongsTo(Doctor::class);
}

public function latestPatientProtocol(): HasOne
{
return $this->hasOne(PatientProtocol::class)
->latestOfMany('created_at');
}

public function patientProtocols(): HasMany
{
return $this->hasMany(PatientProtocol::class);
}
}
<?php

namespace App\Models;

class Patient extends BaseModel
{
public function doctor(): BelongsTo
{
return $this->belongsTo(Doctor::class);
}

public function latestPatientProtocol(): HasOne
{
return $this->hasOne(PatientProtocol::class)
->latestOfMany('created_at');
}

public function patientProtocols(): HasMany
{
return $this->hasMany(PatientProtocol::class);
}
}
<?php

namespace App\Models;

class PatientProtocol extends Model
{
public function patient(): BelongsTo
{
return $this->belongsTo(Patient::class);
}
}
<?php

namespace App\Models;

class PatientProtocol extends Model
{
public function patient(): BelongsTo
{
return $this->belongsTo(Patient::class);
}
}
4 replies
FFilament
Created by N1XN on 8/24/2023 in #❓┊help
Steps in CreateAction sets only last steps formData
When submitting the form and inspecting the before() methods $data only the data from the last step is set, resulting in failed inserts as the data from first step is required. Am I using a relation manager, but this should not be any issue I guess. In the below example $data['milk'] does not exist in before()
use Filament\Forms\Components\Wizard\Step;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables\Actions\CreateAction;

class FoodRelationManager extends RelationManager
{
protected static string $relationship = ‘foods’;

protected static ?string $recordTitleAttribute = 'id';

public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->headerActions([
CreateAction::make('create')
->steps([
Step::make(‘First’)
->columns(2)
->schema([
TextInput::make(‘milk’)
->numeric()
->required(),
]),
Step::make(‘Second’)
->schema([
TextInput::make(‘bread’)
->required(),
]),
])
->before(function ($data) {
return $data;
})
])
->actions([
//
]);
}
}
use Filament\Forms\Components\Wizard\Step;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables\Actions\CreateAction;

class FoodRelationManager extends RelationManager
{
protected static string $relationship = ‘foods’;

protected static ?string $recordTitleAttribute = 'id';

public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->headerActions([
CreateAction::make('create')
->steps([
Step::make(‘First’)
->columns(2)
->schema([
TextInput::make(‘milk’)
->numeric()
->required(),
]),
Step::make(‘Second’)
->schema([
TextInput::make(‘bread’)
->required(),
]),
])
->before(function ($data) {
return $data;
})
])
->actions([
//
]);
}
}
1 replies
FFilament
Created by N1XN on 8/23/2023 in #❓┊help
Disable auth
I would like to disable the built in authentication for filament as I am using breeze with a custom layout. It’s kind of irritating to have two different authentication sites.
7 replies
FFilament
Created by N1XN on 8/17/2023 in #❓┊help
Filter on Stats-Overview
Is there a way to set filters to stat-overviews, like in charts?
5 replies
FFilament
Created by N1XN on 8/15/2023 in #❓┊help
TextInput with Relation best practice?
How do you guys manage relational Forms? As you can see here I want to populate the city on a relational model (address). With this code everything works fine, but I am not sure if this is best practice?
TextInput::make('address.city')
->label('Stadt')
->hint('Geben Sie die Stadt ein.')
->formatStateUsing(function (Model $record) {
return $record->address()->first()?->city;
})
->required(),
TextInput::make('address.city')
->label('Stadt')
->hint('Geben Sie die Stadt ein.')
->formatStateUsing(function (Model $record) {
return $record->address()->first()?->city;
})
->required(),
4 replies
FFilament
Created by N1XN on 8/15/2023 in #❓┊help
Scopes not applied to relations in getEloquentQuery
In my case I have Tenant and Address models that are connected with each other. The Address has tenant_id so a user can only display its own addresses through his own tenant. I have a TenantResource only for admins where all tenants are listed including their address and country code. My issue is that in the code below the getEloquentQuery global scopes get ignored but when defined in the model it works. Isn't this actually the same?
<?php

class Tenant extends BaseTenant
{
public function address(): HasOne
{
// DOES NOT WORK
// return $this->hasOne(Address::class)->oldest();

// WORKS
return $this->hasOne(Address::class)->oldest()->withoutGlobalScopes();
}
}


<?php

class TenantResource extends SuperAdminResource
{
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->with(['address' => function ($query) {
$query->withoutGlobalScope(TenantScope::class)->with('country');
}]);
}
}
<?php

class Tenant extends BaseTenant
{
public function address(): HasOne
{
// DOES NOT WORK
// return $this->hasOne(Address::class)->oldest();

// WORKS
return $this->hasOne(Address::class)->oldest()->withoutGlobalScopes();
}
}


<?php

class TenantResource extends SuperAdminResource
{
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->with(['address' => function ($query) {
$query->withoutGlobalScope(TenantScope::class)->with('country');
}]);
}
}
3 replies