Skip to content

Commit

Permalink
class 12
Browse files Browse the repository at this point in the history
  • Loading branch information
polashmahmud committed Nov 11, 2023
1 parent 9181ac1 commit aff662b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SubscriptionCancelController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware(['auth', 'subscribed']);
}

public function index()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SubscriptionResumeController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware(['auth', 'subscribed']);
}

public function index()
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/Subscriptions/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

class SubscriptionController extends Controller
{
public function __construct()
{
$this->middleware(['auth', 'not.subscribed']);
}

public function index(Request $request)
{
return view('subscriptions.checkout', [
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http;

use App\Http\Middleware\NotSubscribed;
use App\Http\Middleware\Subscribed;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
Expand Down Expand Up @@ -64,5 +66,7 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'subscribed' => Subscribed::class,
'not.subscribed' => NotSubscribed::class,
];
}
24 changes: 24 additions & 0 deletions app/Http/Middleware/NotSubscribed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class NotSubscribed
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if ($request->user() && $request->user()->subscribed('default')) {
return redirect()->route('account.subscriptions');
}

return $next($request);
}
}
23 changes: 23 additions & 0 deletions app/Http/Middleware/Subscribed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class Subscribed
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if ($request->user() && !$request->user()->subscribed('default')) {
return redirect()->route('subscriptions.plans');
}
return $next($request);
}
}

0 comments on commit aff662b

Please sign in to comment.