Skip to content

Commit

Permalink
class 11
Browse files Browse the repository at this point in the history
  • Loading branch information
polashmahmud committed Nov 4, 2023
1 parent 3d2fb51 commit 9181ac1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function index()

public function store(Request $request)
{
$subscription = $request->user()->subscription('default');
$this->authorize('cancel', $subscription = $request->user()->subscription('default'));

$subscription->cancel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function index()

public function store(Request $request)
{
$subscription = $request->user()->subscription('default');
$this->authorize('resume', $subscription = $request->user()->subscription('default'));

$subscription->resume();

Expand Down
19 changes: 19 additions & 0 deletions app/Policies/SubscriptionPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Policies;

use App\Models\User;
use Laravel\Cashier\Subscription;

class SubscriptionPolicy
{
public function cancel(User $user, Subscription $subscription): bool
{
return !$subscription->canceled();
}

public function resume(User $user, Subscription $subscription): bool
{
return $subscription->canceled();
}
}
4 changes: 3 additions & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Providers;

// use Illuminate\Support\Facades\Gate;
use App\Policies\SubscriptionPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Laravel\Cashier\Subscription;

class AuthServiceProvider extends ServiceProvider
{
Expand All @@ -13,7 +15,7 @@ class AuthServiceProvider extends ServiceProvider
* @var array<class-string, class-string>
*/
protected $policies = [
//
Subscription::class => SubscriptionPolicy::class
];

/**
Expand Down
10 changes: 4 additions & 6 deletions resources/views/layouts/account-layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
</ul>

@if(auth()->user()->subscribed())
@if(!auth()->user()->subscription('default')->canceled())
@can('cancel', auth()->user()->subscription('default'))
<ul>
<li><a href="{{ route('account.subscriptions.cancel') }}" class="hover:text-blue-500">Cancel
Subscription</a></li>
</ul>
@endif
@endif
@endcan

@if(auth()->user()->subscribed())
@if(auth()->user()->subscription('default')->canceled())
@can('resume', auth()->user()->subscription('default'))
<ul>
<li><a href="{{ route('account.subscriptions.resume') }}" class="hover:text-blue-500">Resume
Subscription</a></li>
</ul>
@endif
@endcan
@endif
</div>
<div class="col-span-6">
Expand Down

0 comments on commit 9181ac1

Please sign in to comment.