Create RecurringPolicy to protect RecurringController's routes
MODIFY
app/Http/Controllers/RecurringController.php
app/Http/Controllers/RecurringController.php
@@ -24,6 +24,8 @@ class RecurringController extends Controller {
// REEE
}
+ $this->authorize('view', $recurring);
+
return view('recurrings.show', [
'recurring' => $recurring
]);

ADD
app/Policies/RecurringPolicy.php
+<?php
+
+namespace App\Policies;
+
+use App\User;
+use App\Recurring;
+
+class RecurringPolicy {
+ public function view(User $user, Recurring $recurring) {
+ return $user->id === $recurring->user_id;
+ }
+}

MODIFY
app/Providers/AuthServiceProvider.php
app/Providers/AuthServiceProvider.php
@@ -4,6 +4,8 @@ namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
+use App\Policies\RecurringPolicy;
+use App\Recurring;
class AuthServiceProvider extends ServiceProvider
{
@@ -16,6 +18,7 @@ class AuthServiceProvider extends ServiceProvider
'App\Model' => 'App\Policies\ModelPolicy',
'App\Earning' => 'App\Policies\EarningPolicy',
'App\Spending' => 'App\Policies\SpendingPolicy',
+ Recurring::class => RecurringPolicy::class,
'App\Tag' => 'App\Policies\TagPolicy'
];

Create RecurringPolicy to protect RecurringController's routes