Complete reference for the four public macros exposed by plin-code/laravel-full-name and the exceptions they may raise.
The core layer registers two macros on Illuminate\Database\Eloquent\Builder. Both are auto registered by the service provider during packageBooted().
Signature
searchFullName(
string $search,
?string $relation = null,
string $firstNameColumn = 'first_name',
string $lastNameColumn = 'last_name',
): BuilderParameters
$searchis the raw user input. Whitespace is collapsed and the whole string is lowercased before being matched.$relationis an optionalBelongsToorHasOnerelation name on the query's model. When supplied, the search is wrapped inwhereHas.$firstNameColumnand$lastNameColumnoverride the default column names on the target table (the main table when$relationis null, the related table otherwise).
Returns
The same builder for fluent chaining.
Throws
PlinCode\LaravelFullName\Exceptions\UnsupportedRelationExceptionwhen$relationis set but the named relation either does not exist on the model or is neither aBelongsTonor aHasOne.
Examples
Direct columns on the current model.
Person::query()
->searchFullName($request->input('q'))
->paginate();Via a BelongsTo relation.
Booking::query()
->searchFullName($request->input('q'), relation: 'person')
->paginate();Via a HasOne relation. Given User hasOne(Hiker::class):
User::query()
->searchFullName($request->input('q'), relation: 'hiker')
->paginate();With custom column names.
Booking::query()
->searchFullName(
$request->input('q'),
relation: 'person',
firstNameColumn: 'given_name',
lastNameColumn: 'family_name',
)
->paginate();Signature
orderByFullName(
string $direction = 'asc',
?string $relation = null,
string $firstNameColumn = 'first_name',
string $lastNameColumn = 'last_name',
): BuilderParameters
$directionaccepts'asc'or'desc'(case insensitive, trimmed). Any other value raisesInvalidSortDirectionException.$relationis an optionalBelongsToorHasOnerelation name. When supplied, ajoinSubagainst the related model's own query is performed, which preserves global scopes such asSoftDeletes. The join keys are inferred from the relation type:foreignKey = ownerKeyforBelongsTo,localKey = foreignKeyforHasOne.$firstNameColumnand$lastNameColumnoverride the default column names.
Returns
The same builder for fluent chaining.
Throws
InvalidSortDirectionExceptionwhen$directionis neither'asc'nor'desc'.UnsupportedRelationExceptionwhen$relationis set but invalid.
Examples
Direct columns.
Person::query()
->orderByFullName('asc')
->paginate();Via relation.
Booking::query()
->orderByFullName('desc', relation: 'person')
->paginate();Combining search and sort.
Booking::query()
->searchFullName($request->input('q'), relation: 'person')
->orderByFullName('asc', relation: 'person')
->paginate();Note on explicit selects. When $relation is non null the package performs a joinSub. If the caller has already set ->select([...]) on the main query, those selects are preserved. Qualify unqualified column names (test_bookings.id rather than id) to avoid ambiguous column errors from the joined subquery.
The optional layer registers two macros on Filament\Tables\Columns\TextColumn. These macros are only registered if Filament is installed (the service provider checks class_exists(Filament\Tables\Columns\Column::class) before activation).
Signature
fullNameSearchable(
?string $relation = null,
string $firstNameColumn = 'first_name',
string $lastNameColumn = 'last_name',
): staticDelegates to Builder::searchFullName. Same parameters, same exceptions.
Examples
TextColumn::make('full_name')
->fullNameSearchable();
TextColumn::make('user.full_name')
->fullNameSearchable(relation: 'user');
TextColumn::make('full_name')
->fullNameSearchable(
firstNameColumn: 'given_name',
lastNameColumn: 'family_name',
);Signature
fullNameSortable(
?string $relation = null,
string $firstNameColumn = 'first_name',
string $lastNameColumn = 'last_name',
): staticDelegates to Builder::orderByFullName. Direction is supplied by Filament at sort time.
Examples
TextColumn::make('full_name')
->fullNameSortable();
TextColumn::make('user.full_name')
->fullNameSortable(relation: 'user');Extends \InvalidArgumentException. Two named constructors:
UnsupportedRelationException::forMissingRelation(string $relationName, string $modelClass)raised when the named relation method does not exist on the query's model.UnsupportedRelationException::forRelationType(string $relationName, string $modelClass, string $actualType)raised when the relation exists but is neither aBelongsTonor aHasOne(for exampleHasMany,BelongsToMany,MorphTo).
Extends \InvalidArgumentException. One named constructor:
InvalidSortDirectionException::fromDirection(string $direction)raised when the direction supplied toorderByFullNameis not'asc'or'desc'(case insensitive).
Both exceptions are part of the public API. Users may catch either class directly or catch the broader \InvalidArgumentException.