Skip to main content

StoreMembershipRequest

Form request for validating membership creation payloads (assigning a role to a personable, optionally scoped to a memberable).

Namespace

JobMetric\Rolix\Http\Requests\Membership\StoreMembershipRequest

Overview

Validates morph keys, optional role/collection/ownership/expiry, and per-membership allow/deny overlays. There is no withValidator — deeper domain checks (duplicates, memberable/role type match, default role resolution) run in the Membership service.

authorize() returns true.

Validation Rules

FieldRuleDescription
personable_typerequired|stringMorph class / alias of the person (user, etc.)
personable_idrequired|integerPersonable primary key
memberable_typenullable|stringOptional context morph type (tenant, team, …)
memberable_idnullable|integerOptional context morph id
role_idnullable|integer|exists:{rolix.tables.role},idRole to assign; service may fall back to default role when null
collectionnullable|stringLogical collection / bucket
is_ownerbooleanOwner flag within the membership
expired_atnullable|dateSoft expiry for the membership
allowsometimes|arrayExtra allow permissions on this membership
allow.*string
denysometimes|arrayExtra deny permissions on this membership
deny.*string

Attributes

Labels via rolix::base.fields.* for: personable_type, personable_id, memberable_type, memberable_id, role_id, collection, is_owner, expired_at, allow, deny.

withValidator

Not implemented. Only Laravel rules() apply at the FormRequest layer.

Usage Examples

Assign role to a user in a tenant

use JobMetric\Rolix\Facades\Membership;

Membership::store([
'personable_type' => App\Models\User::class,
'personable_id' => 42,
'memberable_type' => App\Models\Tenant::class,
'memberable_id' => 7,
'role_id' => 3,
'collection' => 'staff',
'is_owner' => false,
'expired_at' => null,
'allow' => ['reports.export'],
'deny' => [],
]);

Controller

use JobMetric\Rolix\Http\Requests\Membership\StoreMembershipRequest;
use JobMetric\Rolix\Facades\Membership;
use JobMetric\Rolix\Http\Resources\MembershipResource;

public function store(StoreMembershipRequest $request)
{
$response = Membership::store($request->validated());

return MembershipResource::make($response->getData())
->response()
->setStatusCode(201);
}

Minimal (personable only)

Membership::store([
'personable_type' => App\Models\User::class,
'personable_id' => 1,
// role_id may be resolved to the default role by the service
]);