informer
informer
FFilament
Created by informer on 6/15/2024 in #❓┊help
Am i following good practices?
thanks andrew! will check it out in a min
14 replies
FFilament
Created by informer on 6/15/2024 in #❓┊help
Am i following good practices?
$subscription = new Subscription();

$subscription->start_date = now();
$subscription->user_id = $currentUser;
$subscription->product_id = $license->product_id;

$subscription->end_date = now()->addDays(
$license->expiration_time);

if ($license->product->status
=== ProductStatus::Offline->value)
{
$subscription->paused_at = now();
}

$subscription->save();

if (!is_null($subscription))
{
$license->delete();

Notification::make()
->title('Subscription redeemed.')
->success()
->send();

$this->redirect(
$this->getResource()::getUrl('index'));
}
else
{
Notification::make()
->title('Error happened at redeeming.')
->danger()
->send();
}
})
->form([
Forms\Components\TextInput::make('key')
->label('Key')
->required()
->rules([new \App\Rules\License()]),
]);
}
$subscription = new Subscription();

$subscription->start_date = now();
$subscription->user_id = $currentUser;
$subscription->product_id = $license->product_id;

$subscription->end_date = now()->addDays(
$license->expiration_time);

if ($license->product->status
=== ProductStatus::Offline->value)
{
$subscription->paused_at = now();
}

$subscription->save();

if (!is_null($subscription))
{
$license->delete();

Notification::make()
->title('Subscription redeemed.')
->success()
->send();

$this->redirect(
$this->getResource()::getUrl('index'));
}
else
{
Notification::make()
->title('Error happened at redeeming.')
->danger()
->send();
}
})
->form([
Forms\Components\TextInput::make('key')
->label('Key')
->required()
->rules([new \App\Rules\License()]),
]);
}
14 replies
FFilament
Created by informer on 6/15/2024 in #❓┊help
Am i following good practices?
protected function createReedemAction(): Actions\Action
{
return Actions\Action::make('redeem')
->label('Redeem license')
->action(function (array $data)
{
$currentUser = Auth::user()->id;
$license = License::where('key', $data['key'])->first();

$oldSubscription = Subscription::where(
'product_id', $license->product_id)
->where('user_id', $currentUser)
->first();

if (!is_null($oldSubscription))
{
$oldSubscription->end_date = Carbon::parse(
$oldSubscription->end_date)
->addDays($license->expiration_time);

$oldSubscription->update();
$license->delete();

Notification::make()
->title('Subscription updated')
->success()
->body('Existing subscription updated.')
->send();

return;
}
protected function createReedemAction(): Actions\Action
{
return Actions\Action::make('redeem')
->label('Redeem license')
->action(function (array $data)
{
$currentUser = Auth::user()->id;
$license = License::where('key', $data['key'])->first();

$oldSubscription = Subscription::where(
'product_id', $license->product_id)
->where('user_id', $currentUser)
->first();

if (!is_null($oldSubscription))
{
$oldSubscription->end_date = Carbon::parse(
$oldSubscription->end_date)
->addDays($license->expiration_time);

$oldSubscription->update();
$license->delete();

Notification::make()
->title('Subscription updated')
->success()
->body('Existing subscription updated.')
->send();

return;
}
14 replies
FFilament
Created by informer on 6/15/2024 in #❓┊help
Am i following good practices?
No description
14 replies
FFilament
Created by informer on 6/15/2024 in #❓┊help
Am i following good practices?
I just wanted to know if I was writing decent code, that’s it :(
14 replies