You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use Cog\Contracts\Ban\Bannable as BannableContract;
86
+
use Cog\Laravel\Ban\Traits\Bannable;
84
87
use Illuminate\Foundation\Auth\User as Authenticatable;
85
88
86
-
class User extends Authenticatable implements HasBansContract
89
+
class User extends Authenticatable implements BannableContract
87
90
{
88
-
use HasBans;
91
+
use Bannable;
89
92
}
90
93
```
91
94
92
-
*Note: `HasBans` contract using `CanBeOwner` contract under the hood. If you are using [`cybercog/laravel-ownership`](https://github.com/cybercog/laravel-ownership) package `CanBeOwner` contract could be omitted from bannable model.*
93
-
94
95
### Prepare bannable model database table
95
96
96
97
Bannable model must have `nullable timestamp` column named `banned_at`. This value used as flag and simplify checks if user was banned. If you are trying to make default Laravel User model to be bannable you can use example below.
@@ -133,19 +134,12 @@ class AddBannedAtColumnToUsersTable extends Migration
133
134
#### Apply ban for the entity
134
135
135
136
```php
136
-
$user->bans()->create([]);
137
-
138
137
$user->ban();
139
138
```
140
139
141
-
142
140
#### Apply ban for the entity with reason comment
143
141
144
142
```php
145
-
$user->bans()->create([
146
-
'comment' => 'Enjoy your ban!',
147
-
]);
148
-
149
143
$user->ban([
150
144
'comment' => 'Enjoy your ban!',
151
145
]);
@@ -154,16 +148,18 @@ $user->ban([
154
148
#### Apply ban for the entity which will be deleted over time
155
149
156
150
```php
157
-
$user->bans()->create([
158
-
'expired_at' => '+1 month',
159
-
]);
160
-
161
151
$user->ban([
162
152
'expired_at' => '2086-03-28 00:00:00',
163
153
]);
164
-
```
154
+
```
165
155
166
-
`expired_at` attribute could be `\Carbon\Carbon` instance or any string which could be parsed by `\Carbon\Carbon::parse($string)` method.
156
+
`expired_at` attribute could be `\Carbon\Carbon` instance or any string which could be parsed by `\Carbon\Carbon::parse($string)` method:
To apply query scopes all the time you can define `shouldApplyBannedAtScope` method in bannable model. If method returns `true` all banned models will be hidden by default.
217
213
218
214
```php
219
-
use Cog\Ban\Contracts\HasBans as HasBansContract;
220
-
use Cog\Ban\Traits\HasBans;
215
+
use Cog\Contracts\Ban\Bannable as BannableContract;
216
+
use Cog\Laravel\Ban\Traits\Bannable;
221
217
use Illuminate\Foundation\Auth\User as Authenticatable;
222
218
223
-
class User extends Authenticatable implements HasBansContract
219
+
class User extends Authenticatable implements BannableContract
224
220
{
225
-
use HasBans;
221
+
use Bannable;
226
222
227
223
/**
228
224
* Determine if BannedAtScope should be applied by default.
@@ -238,9 +234,9 @@ class User extends Authenticatable implements HasBansContract
238
234
239
235
### Events
240
236
241
-
If entity is banned `\Cog\Ban\Events\ModelWasBanned` event is fired.
237
+
If entity is banned `\Cog\Laravel\Ban\Events\ModelWasBanned` event is fired.
242
238
243
-
Is entity is unbanned `\Cog\Ban\Events\ModelWasUnbanned` event is fired.
239
+
Is entity is unbanned `\Cog\Laravel\Ban\Events\ModelWasUnbanned` event is fired.
244
240
245
241
### Middleware
246
242
@@ -250,7 +246,7 @@ To use it define new middleware in `$routeMiddleware` array of `app/Http/Kernel.
- Delete `database/migrations/2017_03_04_000000_create_ban_table.php` migration file (from v3 service provider automatically loading migration files or republish it if custom changes are required to be done).
0 commit comments