I would recommend adding a is_banned
boolean column to your users table.
This way, when you ban a user, you would do two things:
Once you do that, you can get all non-banned users by doing this:
// Add to Users model
protected $casts = ['is_banned' => 'boolean'];
// Eloquent query to get all non-banned users.
$users = Users::orderBy('id', 'desc')->where('is_banned', '=', false)->paginate(6);
I'm questioning why you would want another table? I can't think of a good reason. And you have to deal with keeping the integrity between two tables. If you truly want another table then I would make a Banned model and relate it with a hasOne.
// user model
public function banned()
{
return hasOne('Banned');
}
// then query
$users = Users::has('banned', '=', 0)->get();
But again I question why you would have a separate table.
@rickshawhobo It depends on what he wants to do. A banned user doesn't just have to be a binary thing (banned and unbanned).
You might want to know who banned the user, when he was banned, how long he will be banned, etc. You might want to track his history or keep a list of reasons as to why he was banned.
@thomastkim @rickshawhobo I already have a is_banned column, but as you said, I need to have some informations about the banned users, like timestamps, reasons, ip...
Thank you for your suggestions! I used it and it's working!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community