shaan
shaan
Explore posts from servers
FFilament
Created by shaan on 7/1/2024 in #❓┊help
Slow Query - Slow Endpoints in Filamentphp v3
php lass Letter extends Model
{
use HasFactory;
use SoftDeletes;

protected $guarded = [];

protected $casts = [
'status' => LetterStatus::class,
'verified_at' => 'date',
'approved_at' => 'date',
];

protected static function booted(): void
{
static::creating(function ($model) {
$model->user_id = Auth::user()->id;
$model->status = LetterStatus::Pending;
});
}

public function user()
{
return $this->belongsTo(User::class);
}

public function template(): BelongsTo
{
return $this->belongsTo(LetterTemplate::class, 'template_id');
}

public function verifiedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'verified_by');
}

public function approvedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'approved_by');
}

protected function daysRemaining(): Attribute
{
return Attribute::make(
get: function ($value, $attributes) {
if ($this->status === LetterStatus::Approved) {
return '';
}

$createdAt = Carbon::parse($this->created_at);
$dueDate = $createdAt->addDays($this->template->eta);
$daysRemaining = $dueDate->diffInDays(now(), false);

if ($daysRemaining < 0) {
return 'Overdue in '.abs($daysRemaining).' days';
} elseif ($daysRemaining == 0) {
return 'Due today';
} else {
return $daysRemaining.' days';
}
}
);
}
}
php lass Letter extends Model
{
use HasFactory;
use SoftDeletes;

protected $guarded = [];

protected $casts = [
'status' => LetterStatus::class,
'verified_at' => 'date',
'approved_at' => 'date',
];

protected static function booted(): void
{
static::creating(function ($model) {
$model->user_id = Auth::user()->id;
$model->status = LetterStatus::Pending;
});
}

public function user()
{
return $this->belongsTo(User::class);
}

public function template(): BelongsTo
{
return $this->belongsTo(LetterTemplate::class, 'template_id');
}

public function verifiedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'verified_by');
}

public function approvedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'approved_by');
}

protected function daysRemaining(): Attribute
{
return Attribute::make(
get: function ($value, $attributes) {
if ($this->status === LetterStatus::Approved) {
return '';
}

$createdAt = Carbon::parse($this->created_at);
$dueDate = $createdAt->addDays($this->template->eta);
$daysRemaining = $dueDate->diffInDays(now(), false);

if ($daysRemaining < 0) {
return 'Overdue in '.abs($daysRemaining).' days';
} elseif ($daysRemaining == 0) {
return 'Due today';
} else {
return $daysRemaining.' days';
}
}
);
}
}
4 replies
FFilament
Created by shaan on 7/1/2024 in #❓┊help
Slow Query - Slow Endpoints in Filamentphp v3
php public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListLetters::route('/'),
'create' => Pages\CreateLetter::route('/create'),
'view' => Pages\ViewLetter::route('/{record}'),
'edit' => Pages\EditLetter::route('/{record}/edit'),
];
}

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
// ->with(['user', 'template', 'verifiedBy', 'approvedBy'])
// ->where(function ($query) {
// $user = auth()->user();
// $userId = $user->id;
//
// $query->where('user_id', $userId);
//
// if ($user->can('verifyAny', Letter::class)) {
// $query->orWhereIn('status', ['pending', 'verified', 'approved']);
// } elseif ($user->can('approveAny', Letter::class)) {
// $query->orWhere('status', 'verified');
// }
// })
// ->latest('created_at')
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
php public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListLetters::route('/'),
'create' => Pages\CreateLetter::route('/create'),
'view' => Pages\ViewLetter::route('/{record}'),
'edit' => Pages\EditLetter::route('/{record}/edit'),
];
}

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
// ->with(['user', 'template', 'verifiedBy', 'approvedBy'])
// ->where(function ($query) {
// $user = auth()->user();
// $userId = $user->id;
//
// $query->where('user_id', $userId);
//
// if ($user->can('verifyAny', Letter::class)) {
// $query->orWhereIn('status', ['pending', 'verified', 'approved']);
// } elseif ($user->can('approveAny', Letter::class)) {
// $query->orWhere('status', 'verified');
// }
// })
// ->latest('created_at')
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
4 replies
FFilament
Created by shaan on 7/1/2024 in #❓┊help
Slow Query - Slow Endpoints in Filamentphp v3
php class ListLetters extends ListRecords
{
protected static string $resource = LetterResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()->label('New Request')->icon('heroicon-o-plus-circle'),
];
}

protected function paginateTableQuery(Builder $query): Paginator
{
return $query->simplePaginate(($this->getTableRecordsPerPage() === 'all') ? $query->count() : $this->getTableRecordsPerPage());
}
}
php class ListLetters extends ListRecords
{
protected static string $resource = LetterResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()->label('New Request')->icon('heroicon-o-plus-circle'),
];
}

protected function paginateTableQuery(Builder $query): Paginator
{
return $query->simplePaginate(($this->getTableRecordsPerPage() === 'all') ? $query->count() : $this->getTableRecordsPerPage());
}
}
4 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
Thank You
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
INFO Processing jobs from the [default] queue.

2024-06-26 01:05:15 App\Jobs\ProcessLetterApproval ..................................................................................... RUNNING 2024-06-26 01:05:15 App\Jobs\ProcessLetterApproval ............................................................................... 111.99ms DONE 2024-06-26 01:05:15 App\Jobs\GeneratePdfForLetter ...................................................................................... RUNNING 2024-06-26 01:05:22 App\Jobs\GeneratePdfForLetter ...................................................................................... 6s DONE 2024-06-26 01:05:22 App\Jobs\SendLetterNotification .................................................................................... RUNNING 2024-06-26 01:05:22 App\Jobs\SendLetterNotification .............................................................................. 101.98ms DONE 2024-06-26 01:05:22 Filament\Notifications\DatabaseNotification ........................................................................ RUNNING 2024-06-26 01:05:22 Filament\Notifications\DatabaseNotification ................................................................... 55.69ms DONE
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
yes. it is. changed to database, migrated. now i think its ok
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
this is whats showing
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
php artisan queue:work INFO Processing jobs from the [default] queue.
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
hehe. good point 🙂 . however, i cant go back to other letters when its running. thats the issue
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
if its a job, then i can just press approve and get on with other operations right? Job will update the status and generate the letter and then notification will be send?
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
around 6 to 10 sec. and sometimes exceed error max 30
16 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
php artisan queue:work
16 replies
FFilament
Created by shaan on 6/17/2024 in #❓┊help
Editor js or full featured editor for filament
thank you
4 replies
FFilament
Created by shaan on 6/7/2024 in #❓┊help
is there any titleCase() for filament tables?
🙂 thank you
6 replies
FFilament
Created by shaan on 6/7/2024 in #❓┊help
is there any titleCase() for filament tables?
this is the right one
6 replies
FFilament
Created by shaan on 6/7/2024 in #❓┊help
is there any titleCase() for filament tables?
->formatStateUsing(fn (string $state): string => str($state)->title()),
6 replies
FFilament
Created by shaan on 6/7/2024 in #❓┊help
is there any titleCase() for filament tables?
Method Illuminate\Support\Stringable::titleCase does not exist.
6 replies
TLCTuto's Laravel Corner
Created by shaan on 8/29/2023 in #🚀laravel
Fetch data from API and fill form
7 replies
TLCTuto's Laravel Corner
Created by shaan on 10/30/2023 in #💡filament
Old value after failed validation
oh, this is a old project. will start a filament one soon 😄
3 replies
TLCTuto's Laravel Corner
Created by shaan on 8/29/2023 in #🚀laravel
Fetch data from API and fill form
yes. Thank you so much for the help 🙂
7 replies