›
byrcsc/laravel-checklist · 1.x
Attach comments and multi-stage approval to checklists through polymorphic relations.
Laravel Checklist depends on no sibling package, and none of them depends on it. Sibling models reference a checklist, a version, or a single answer through polymorphic relations. Neither package needs to know about the other's models.
The models in this package are final. You cannot add a sibling's trait to
Checklist or Response, so the convenience methods those traits provide are
not available on them.
Write the relation from the sibling's side instead, which is one or two extra lines. When you want the shorter syntax, put the trait on your own model, such as the vehicle, work order, or shift. Let that model carry the relation.
Create the comment against the morph keys:
use ByRcsc\LaravelComments\Models\Comment;
Comment::query()->create([
'commentable_type' => $checklist->getMorphClass(),
'commentable_id' => $checklist->getKey(),
'commentator_type' => $inspector->getMorphClass(),
'commentator_id' => $inspector->getKey(),
'body' => 'Tyre pressure looks low in the photo. Recheck before the run.',
]);Reading them back is an ordinary morph query, and the sibling's own scopes apply unchanged:
Comment::query()
->where('commentable_type', $checklist->getMorphClass())
->where('commentable_id', $checklist->getKey())
->topLevel()
->with('replies')
->get();Comment on a Response rather than the whole checklist when the discussion is
about one answer. A comment can reference the response through the same
polymorphic relation. The thread then survives the checklist being reopened and
resubmitted.
The review() step in this package is deliberately lightweight: one reviewer,
one outcome, one timestamp. When sign-off needs stages, quorums, delegation, or
escalation, run the approval package over your own record and treat the
checklist as the evidence:
use ByRcsc\LaravelApproval\Concerns\Approvable;
class SafetyRelease extends Model
{
use Approvable;
public function checklist(): BelongsTo
{
return $this->belongsTo(\ByRcsc\LaravelChecklist\Models\Checklist::class);
}
}$release = SafetyRelease::create(['checklist_id' => $checklist->id]);
$release->submitForApproval('safety-release');Gate the submission on the checklist rather than duplicating its rules:
if (! $checklist->isClosed() || $checklist->passed !== true) {
abort(422, 'The inspection has not passed.');
}Wiring this to the checklist's own lifecycle takes one listener on
ChecklistCompleted.
review() records and
when isClosed() is true.