Andrew Wallo
Andrew Wallo
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
Maybe I’m just confused on what your talking about then
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
Yeah exactly. Then how would you store the users preference for the language? You would need to use Google Translate or something
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
But then again the specified language isn’t stored for a user in the database
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
You can try storing it in the browser/session
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
Oh well yeah.. that’s probably why you can’t have multi language easily because the users specified language isn’t tied to them
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
What’s your definition of a frontend
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
What do you mean it has a frontend?
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
Per tenant
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
It has multi language support
32 replies
FFilament
Created by Nemesisesq on 6/17/2024 in #❓┊help
Can I use filament to build sites other than Admin Panels?
You can do it if you have multitenancy or just if you have users. Check out https://github.com/andrewdwallo/erpsaas
32 replies
FFilament
Created by informer on 6/15/2024 in #❓┊help
Am i following good practices?
private function findLicense(string $key): ?License
{
return License::with('product')->where('key', $key)->first();
}

private function sendNotification(string $message, string $type = 'success'): void
{
Notification::make()
->title($message)
->status($type)
->send();
}

private function findOldSubscription(int $productId, int $userId): ?Subscription
{
return Subscription::where('product_id', $productId)
->where('user_id', $userId)
->first();
}

private function updateOldSubscription(Subscription $oldSubscription, License $license): void
{
$oldSubscription->end_date = Carbon::parse($oldSubscription->end_date)
->addDays($license->expiration_time);
$oldSubscription->update();
}

private function createNewSubscription(License $license, int $userId): void
{
$subscription = new Subscription();
$subscription->start_date = now();
$subscription->user_id = $userId;
$subscription->product_id = $license->product_id;
$subscription->end_date = now()->addDays($license->expiration_time);

if ($license->product->status === ProductStatus::Offline->value) { // could use just ProductStatus::Offline here instead of chaining ->value
$subscription->paused_at = now();
}

if ($subscription->save()) {
$this->deleteLicenseAndNotify($license, 'Subscription redeemed.');
$this->redirect($this->getResource()::getUrl('index'));
} else {
$this->sendNotification('Error happened at redeeming.', 'danger');
}
}

private function deleteLicenseAndNotify(License $license, string $message): void
{
$license->delete();
$this->sendNotification($message);
}
private function findLicense(string $key): ?License
{
return License::with('product')->where('key', $key)->first();
}

private function sendNotification(string $message, string $type = 'success'): void
{
Notification::make()
->title($message)
->status($type)
->send();
}

private function findOldSubscription(int $productId, int $userId): ?Subscription
{
return Subscription::where('product_id', $productId)
->where('user_id', $userId)
->first();
}

private function updateOldSubscription(Subscription $oldSubscription, License $license): void
{
$oldSubscription->end_date = Carbon::parse($oldSubscription->end_date)
->addDays($license->expiration_time);
$oldSubscription->update();
}

private function createNewSubscription(License $license, int $userId): void
{
$subscription = new Subscription();
$subscription->start_date = now();
$subscription->user_id = $userId;
$subscription->product_id = $license->product_id;
$subscription->end_date = now()->addDays($license->expiration_time);

if ($license->product->status === ProductStatus::Offline->value) { // could use just ProductStatus::Offline here instead of chaining ->value
$subscription->paused_at = now();
}

if ($subscription->save()) {
$this->deleteLicenseAndNotify($license, 'Subscription redeemed.');
$this->redirect($this->getResource()::getUrl('index'));
} else {
$this->sendNotification('Error happened at redeeming.', 'danger');
}
}

private function deleteLicenseAndNotify(License $license, string $message): void
{
$license->delete();
$this->sendNotification($message);
}
14 replies
FFilament
Created by informer on 6/15/2024 in #❓┊help
Am i following good practices?
This is an opinionated answer but I have refactored your code to make it follow "best practices" in Laravel/PHP:
protected function createReedemAction(): Actions\Action
{
return Actions\Action::make('redeem')
->label('Redeem license')
->action(function (array $data): void {
$currentUser = Auth::user()->id;
$license = $this->findLicense($data['key']);

if ($license === null) {
$this->sendNotification('Invalid License Key', 'danger');
return;
}

DB::transaction(function () use ($license, $currentUser): void {
$oldSubscription = $this->findOldSubscription($license->product_id, $currentUser);

if ($oldSubscription) {
$this->updateOldSubscription($oldSubscription, $license);
$this->deleteLicenseAndNotify($license, 'Existing subscription updated.');
} else {
$this->createNewSubscription($license, $currentUser);
}
});
})
->form([
Forms\Components\TextInput::make('key')
->label('Key')
->required()
->rules([new \App\Rules\License()]),
]);
}
protected function createReedemAction(): Actions\Action
{
return Actions\Action::make('redeem')
->label('Redeem license')
->action(function (array $data): void {
$currentUser = Auth::user()->id;
$license = $this->findLicense($data['key']);

if ($license === null) {
$this->sendNotification('Invalid License Key', 'danger');
return;
}

DB::transaction(function () use ($license, $currentUser): void {
$oldSubscription = $this->findOldSubscription($license->product_id, $currentUser);

if ($oldSubscription) {
$this->updateOldSubscription($oldSubscription, $license);
$this->deleteLicenseAndNotify($license, 'Existing subscription updated.');
} else {
$this->createNewSubscription($license, $currentUser);
}
});
})
->form([
Forms\Components\TextInput::make('key')
->label('Key')
->required()
->rules([new \App\Rules\License()]),
]);
}
14 replies
FFilament
Created by Andrew Wallo on 6/8/2024 in #❓┊help
Help Needed with Sorting an Accessor in Filament Table
Probably the best choice in this case
9 replies
FFilament
Created by Andrew Wallo on 6/8/2024 in #❓┊help
Help Needed with Sorting an Accessor in Filament Table
Okay thank you for your help and suggestions. I suppose I just won't make it a sortable.
9 replies
FFilament
Created by Mike on 5/16/2024 in #❓┊help
Viewfield not updating state
Or why is there even a need to pass view data if you can use the $state of the form field for post_content in the view?
8 replies
FFilament
Created by Mike on 5/16/2024 in #❓┊help
Viewfield not updating state
You probably need to somehow pass the view data through a closure..
8 replies
FFilament
Created by LeviBeezy on 5/14/2024 in #❓┊help
getTabs v3.2.77 error: trim(): Argument #1 ($string) must be of type string, Filament\Support\Enums\
What theme is this?
13 replies
FFilament
Created by YusifHajiyev on 11/29/2023 in #❓┊help
TopNavigation
Try this and see what happens:
.fi-topbar > nav {
@apply relative flex justify-center;

> ul {
@apply absolute -translate-x-2/4 gap-x-0 left-2/4;
}

> div {
@apply static;
}
}
.fi-topbar > nav {
@apply relative flex justify-center;

> ul {
@apply absolute -translate-x-2/4 gap-x-0 left-2/4;
}

> div {
@apply static;
}
}
5 replies
FFilament
Created by YusifHajiyev on 11/29/2023 in #❓┊help
TopNavigation
Maybe look at the fi-topbar > nav css applied classes in here: https://github.com/andrewdwallo/erpsaas/blob/2.x/resources/css/filament/company/theme.css
5 replies
FFilament
Created by YusifHajiyev on 11/29/2023 in #❓┊help
TopNavigation
Your gonna have to use css
5 replies