Models

Introduction

TranquilModel extends Eloquent Model and provides sensible defaults and helpers for appends and validation.

Key Features

  • Guarded: id, created_at, updated_at, deleted_at
  • timestamps enabled
  • snakeAttributes disabled (public static $snakeAttributes = false)
  • Appends scoping helpers to control appended accessors on a per-query basis
  • Validation via HasValidation trait

Appends Control

1$model->toArray(); // includes appends
2 
3// Temporarily override appends for the current query scope
4Car::query()->overrideAppends(['fullName'])->get();
5 
6// Add appends for the current query scope
7Car::query()->addAppends(['fullName', 'summary'])->get();
8 
9// Remove appends for the current query scope
10Car::query()->withoutAppends()->get();

Validation

TranquilModel uses HasValidation. Override these on your model:

1public function getValidationRules(): array
2{
3 return [
4 'make' => ['required', 'string'],
5 'model' => ['required', 'string'],
6 'year' => ['required', 'integer', 'min:1900'],
7 ];
8}
9 
10public function getDefaultValidationAttributes(): array
11{
12 return [
13 'make' => '',
14 'model' => '',
15 'year' => null,
16 ];
17}

TranquilUser

An authenticatable user model offering role utilities (hasRole, addRole/removeRole, hasAllRoles, scopes whereHasRole/whereHasAllRoles). It also defines default validation rules and a computed name attribute. See more