Check out Laravel Permissions from Spatie. That package lets you define permissions and then group permissions into roles and give permissions and roles to any model in your system. So you can have a permission that says $user->can('create models')
Alternatively, instead of creating a bunch of different permissions and roles, you can simply create a table that stores the limits by plan in rows like this:
id plan post_limit contact_limit
1 basic 5 5
2 premium 10 10
...
and then link that to a user on the users table:
id name plan_id
1 John Doe 1
so that in your User model you can check to see what plan they have, and you can write custom methods like postLimitReached
public function postLimitReached(): bool
{
return $this->posts()->count() < $this->plan->post_limit;
}
so that in your PostController you can check if a user is allowed to create a new post:
public function create()
{
$user = Auth::user();
if($user->postLimitReached()) {
//forbidden
//but you can handle this however
abort(403);
} else {
//show the form to create a new post
}
}