Download the PHP package coyote6/laravel-base without Composer

On this page you can find all versions of the php package coyote6/laravel-base. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-base

Laravel Base

A collection of small Laravel traits and helpers — mainly Eloquent model creation-time conventions (author/client/machine name/slug stamping), select-option helpers, and a couple of database/file utilities.

Installation

The service provider (Coyote6\LaravelBase\Providers\BaseServiceProvider) is auto-discovered and merges this package's config under the coyote6-base key automatically. Publishing is optional, only needed to override the defaults:

This publishes config/coyote6-base.php into your application.

Upgrade From 0.2.7

v0.3.0 is a breaking release. See CHANGELOG.md for the full old-namespace → new-namespace table — every trait moved, and four were renamed (HasAuthor/HasClient/HasMachineName/HasMachineNameAsId → Author/Client/MachineName/MachineNameAsId). There's no deprecation shim; it's a hard cutover.

Those four new names are short and generic enough to routinely collide with a real domain class already living in an app being upgraded — Client and Author are common model names. So the upgrade command below always imports them aliased (BootAuthor/BootClient/BootMachineName/ BootMachineNameAsId) rather than bare, regardless of whether this particular file happens to collide today. This is specific to the automated upgrade path; a fresh install has no such history to protect against, so Creation Helpers below documents the plain, unaliased names as the default — alias by hand only if your own app also has a class by the same name.

Automating the namespace rename. This package ships a command that scans your application and rewrites old trait references to whatever the current version needs:

It scans app/ and database/ by default (comma-separate --path to scan somewhere else, e.g. --path=app,database,routes), then runs every upgrade step it knows about, one at a time — currently just the v0.2.7 → v0.3.0 rename below, but future breaking releases will add their own step here, so running this command again after a later update only applies whatever's actually new. Each step reports on its own:

Answer yes to write that step's changes, or no to leave them untouched and move on to the next step. Pass --apply to skip the prompt and write immediately instead — useful in CI or any other non-interactive context:

A step with nothing left to do prints No file changes found. and moves on without asking anything, so it's safe to re-run this command at any time, even after it's already been applied.

It rewrites both the use import statement and the bare use ShortName; trait-inclusion line inside a class body, for every renamed/moved trait — including an aliased import (use Coyote6\LaravelBase\Traits\HasAuthor as Whatever;), which keeps your alias and only swaps the underlying namespace. HasAuthor/HasClient/HasMachineName/HasMachineNameAsId are always rewritten aliased as BootAuthor/BootClient/ BootMachineName/BootMachineNameAsId, per the naming note above, even in files where the bare name wouldn't currently collide with anything — so the same trait always reads the same way everywhere in your codebase, and you never have to wonder why one file says Client and another says BootClient.

Two situations it can't safely handle automatically:

Review the diff and run your own test suite before committing — this is a straightforward textual rewrite, not a full PHP-aware refactor, so give it a look rather than trusting it blindly on generated or unusually formatted code.

If your database columns don't match the new defaults. BootAuthor, BootClient, BootMachineName, BootMachineNameAsId, and Slug used to hardcode which attribute they read from/wrote to (author_id, client_id, machine_name, name). Those are now config-driven (field/reference under each section — see Configuration below), and the defaults match the old hardcoded names exactly, so most upgrades need no config changes at all. If any of your tables already used different column names for these before upgrading, publish the config and point field/reference at your existing columns instead of renaming the database.

Example below changes the default field name, author_id to user_id. This was hardcoded to 'author_id' before v0.3.0

machine_name's default generation method changed. Before v0.3.0, BootMachineName/BootMachineNameAsId always lowercased and replaced every non-alphanumeric character with an underscore — snake_case-shaped output. The new default is strictKebab (dash-separated), since that's now the package-wide default machine_name.method — see coyote6/laravel-str for what strictKebab and the other available methods actually do. If your existing machine_name values (or anything reading them) depend on the old underscore-separated format, publish the config and set machine_name.method explicitly to whichever option in the Method table matches what you already have — otherwise newly-created records will get dash-separated values alongside your existing underscore-separated ones.

The upgrade command surfaces this itself rather than leaving it to this paragraph: if this run's scan finds machine-name generation in use at all (under either the old or new trait name, so this still fires on a second run after the rename itself already landed), it checks whether coyote6-base's config is published yet, offers to publish it if not, then asks which machine_name.method this app should use — defaulting to whatever the config already has, so pressing enter keeps the current value:

Picking a different method updates the published config's machine_name.method line directly (a targeted text swap, not a full rewrite of the file, so the config's own per-method documentation comments are left alone). Never asked under --apply; it prints the same reminder instead and leaves the config untouched.

Upgrade From 1.0.0

v2.0.0 is a breaking release: every BootTraits convention method was renamed from its old create* verb to assign*...OnModelCreation, to make explicit that it assigns a value (unless one is already present) rather than creating anything, and that it fires on Eloquent's creating event.

Old New
createAuthor assignAuthorOnModelCreation
createOriginalAuthor assignOriginalAuthorOnModelCreation
createClient assignClientOnModelCreation
createMachineName assignMachineNameOnModelCreation
createSlug assignSlugOnModelCreation

Owner/User are new in this same release and already ship with the assign*OnModelCreation names — there's nothing to migrate for either.

Most apps should be unaffected as BootTraits calls these methods internally by name, so a model that only composes one of the Boot/* traits (never defining or calling the method itself) picks up the new name automatically, with no code changes needed. This only matters if your own code manually defines one of these methods (to opt into the BootTraits convention without using the trait), overrides one of these trait methods, or calls one directly.

The same php artisan coyote6-base:upgrade command documented above picks this up as its own step — re-running it after upgrading also runs Running v2.0.0 upgrades, renaming both the method definition and any -> call site, and leaving already-renamed code untouched (safe to run repeatedly). No deprecation shim ships for the old names.

Upgrade From 2.0.0

v2.1.0 deprecates the GetAsOptionsAbbr trait. GetAsOptions::getAsOptions() now takes a $key (plus $field, $limit, $page, $modifyQuery), so one trait covers an abbr-keyed list too — getAsOptions('abbr'). GetAsOptionsAbbr::getAsOptions() still works, now as a shim over getAsOptions('abbr') that raises an E_USER_DEPRECATED notice on every call, so nothing breaks the moment you upgrade — the migration can happen on your schedule.

The same php artisan coyote6-base:upgrade command handles it as its Running v2.1.0 upgrades step. For every model composing GetAsOptionsAbbr it swaps the trait for GetAsOptions (import and class-body use, keeping any as alias), and then across every scanned file — so point --path at everything that could call these models, e.g. --path=app,resources — it adds 'abbr' as the first argument to each no-argument Model::getAsOptions() call it can resolve to one of those models (imported, same-namespace, or fully qualified), plus any self::/static::/$this-> call in the model's own file. Idempotent and safe to re-run.

It deliberately leaves three things for you, reporting each with the file path:

Directory Structure

Configuration

All config lives under the coyote6-base key. Every field/reference option is just the attribute name to read from or write to — override any of them per-application via the published config file.

Key Default Used by
machine_name.field machine_name MachineName (destination attribute; MachineNameAsId always targets the primary key instead)
machine_name.reference name MachineName, MachineNameAsId (source attribute)
machine_name.method strictKebab ResolvesMachineName — which Str:: method/macro generates the value
machine_name.method_parameters null ResolvesMachineName — extra arguments passed to machine_name.method, if any
author.field author_id Author
original_author.field original_author_id OriginalAuthor
owner.field owner_id Owner
user.field user_id User
client.field client_id Client (destination attribute)
client.reference client_id Client, getCurrentUserClientId() (attribute read off the current user)
slug.field slug Slug (destination attribute)
slug.reference name Slug (source attribute)
slug.separator - Slug — Str::slug()'s $separator
slug.language en Slug — Str::slug()'s $language
slug.dictionary ['@' => 'at'] Slug — Str::slug()'s $dictionary

machine_name.method always runs through Str::ascii() first, regardless of which method is selected. Allowed values: strictKebab (default), strictSnake, pureKebab, pureSnake, kebab, snake, dot, slug, studly, pascal, camel, lower, upper, deduplicate, transliterate — see the config file's own comments for per-method examples and parameters (machine_name.method_parameters).

Available Traits

Boot Method

Coyote6\LaravelBase\Traits\Models\BootTraits — registers Eloquent model-event listeners (creating, created, updating, updated, deleting, deleted) that call a matching convention method on the model if it exists: assignAuthorOnModelCreation, assignOriginalAuthorOnModelCreation, assignOwnerOnModelCreation, assignUserOnModelCreation, assignClientOnModelCreation, assignMachineNameOnModelCreation, assignSlugOnModelCreation on creating; modelCreating/modelCreated/modelUpdating/modelUpdated/modelDeleting/modelDeleted at their respective events. A model opts into any of this just by defining the method — directly, or via one of the Boot/* traits below — BootTraits itself never requires any of them to exist.

For UUID primary keys, use Laravel's native Illuminate\Database\Eloquent\Concerns\HasUuids trait — this package no longer ships its own Uuid method.

Creation Helpers (require BootTraits)

All under Coyote6\LaravelBase\Traits\Models\Boot:

It is recommended to always alias the traits to prevent class name collisions. For instance, if your model already has its own User/Client/etc. class reference then adding the short name of the matching class is likely to create an issue. The User trait is a perfect and very common example of this issue.

Nearly every Laravel app has its own App\Models\User. Because the User::class is commonly in the same namespace as the other models, it may be common for a developer to reference the User model directly without an explicit use statement (e.g. a belongsTo(User::class)). If you were to add use ...\Boot\User without the alias, then the trait will override the shared namespace model and cause errors. If the model already has an explicit use statement (e.g. use App\Models\User;), it will throw a fatal error instead.

For that reason, we always recommend aliasing the Boot/* traits on import (use ...\Boot\User as BootUser;).

Select Dropdown/Radio Button Helpers

Both under Coyote6\LaravelBase\Traits\Models, and both expose the same method name getAsOptions() — use one or the other, never both together on the same model:

Nothing is cached — every call queries the database, so the column selection, order, page, and data are always current. Assign the result to a variable if one request needs it more than once.

Query Helpers

Database Helpers

Both under Coyote6\LaravelBase\Traits\Database:

File Helpers

Global Helper Functions

Defined in src/Helpers/Helpers.php, autoloaded globally (no namespace):

Examples

Author, Client, MachineName, and Slug together

app/Models/Example.php

On create, this fills author_id and client_id from the current user, and generates machine_name/slug from name — all only when not already set. BootTraits is what actually wires assignAuthorOnModelCreation()/assignClientOnModelCreation()/assignMachineNameOnModelCreation()/assignSlugOnModelCreation() into Eloquent's creating event; it must be included alongside the others.

OriginalAuthor

Add alongside Author for a permanent, foreign-key-free record of the original author (useful when author_id has an ON DELETE SET NULL foreign key and could later be nulled out):

MachineNameAsId

When the machine name itself should be the primary key, use MachineNameAsId instead of MachineName:

Overriding config

config/coyote6-base.php (after php artisan vendor:publish --tag=coyote6-base-config):

Get As Options

app/Models/Example.php

app/Http/Controllers/ExampleController.php

Options Keyed Or Labelled By Another Field

getAsOptions(string $key = 'id', string $field = 'name', int $limit = 0, int $page = 1, ?Closure $modifyQuery = null). $key is the array key, $field the label, $limit/$page paginate, and $modifyQuery is a closure handed the query builder before it runs — filter (where, whereIn, whereHas, a scope), re-order, whatever. When you pass it, it owns the ordering (the default $field ascending is not applied), so a filter-only closure should add its own orderBy. Any column works — abbr for states or countries, a code, a slug, etc.:

Every parameter has a default, so use named arguments to set just the one (or few) you need without spelling out the earlier ones or remembering their order:

app/Models/Example.php

Deprecated: the GetAsOptionsAbbr trait still works — as a shim over getAsOptions('abbr') that raises an E_USER_DEPRECATED notice — but there is no longer a reason to use it. Swap use GetAsOptionsAbbr; for use GetAsOptions; and pass 'abbr' at the call site.

Get By Slug

app/Models/Example.php

app/Http/Controllers/ExampleController.php

DropsIndexes

database/migrations/2024_01_01_000000_example_migration.php

ServiceProviderSeedsDb

app/Providers/AppServiceProvider.php

Every seeder class found in that directory now also runs whenever php artisan db:seed runs.

ReadsCsv


All versions of laravel-base with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
coyote6/laravel-str Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package coyote6/laravel-base contains the following files

Loading the files please wait ...