diff --git a/app/Http/Controllers/Account/Subscriptions/SubscriptionCancelController.php b/app/Http/Controllers/Account/Subscriptions/SubscriptionCancelController.php index dfc6c6e..919355c 100644 --- a/app/Http/Controllers/Account/Subscriptions/SubscriptionCancelController.php +++ b/app/Http/Controllers/Account/Subscriptions/SubscriptionCancelController.php @@ -9,7 +9,7 @@ class SubscriptionCancelController extends Controller { public function __construct() { - $this->middleware('auth'); + $this->middleware(['auth', 'subscribed']); } public function index() diff --git a/app/Http/Controllers/Account/Subscriptions/SubscriptionResumeController.php b/app/Http/Controllers/Account/Subscriptions/SubscriptionResumeController.php index 86c4671..4040434 100644 --- a/app/Http/Controllers/Account/Subscriptions/SubscriptionResumeController.php +++ b/app/Http/Controllers/Account/Subscriptions/SubscriptionResumeController.php @@ -9,7 +9,7 @@ class SubscriptionResumeController extends Controller { public function __construct() { - $this->middleware('auth'); + $this->middleware(['auth', 'subscribed']); } public function index() diff --git a/app/Http/Controllers/Subscriptions/SubscriptionController.php b/app/Http/Controllers/Subscriptions/SubscriptionController.php index f888510..cebc8b1 100644 --- a/app/Http/Controllers/Subscriptions/SubscriptionController.php +++ b/app/Http/Controllers/Subscriptions/SubscriptionController.php @@ -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', [ diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 494c050..920bfe1 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -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 @@ -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, ]; } diff --git a/app/Http/Middleware/NotSubscribed.php b/app/Http/Middleware/NotSubscribed.php new file mode 100644 index 0000000..1c40bd6 --- /dev/null +++ b/app/Http/Middleware/NotSubscribed.php @@ -0,0 +1,24 @@ +user() && $request->user()->subscribed('default')) { + return redirect()->route('account.subscriptions'); + } + + return $next($request); + } +} diff --git a/app/Http/Middleware/Subscribed.php b/app/Http/Middleware/Subscribed.php new file mode 100644 index 0000000..faba702 --- /dev/null +++ b/app/Http/Middleware/Subscribed.php @@ -0,0 +1,23 @@ +user() && !$request->user()->subscribed('default')) { + return redirect()->route('subscriptions.plans'); + } + return $next($request); + } +}