dan / laravel-more
More for your Laravel projects.
Package info
github.com/DataAndNumbersOrganization/laravel-more
Type:project
pkg:composer/dan/laravel-more
v0.3.1
2022-03-16 14:47 UTC
Requires
- php: >=7.0
- illuminate/database: ^5.5|^6.0|^7.0|^8.0
- illuminate/support: ^5.5|^6.0|^7.0|^8.0
This package is auto-updated.
Last update: 2026-06-30 14:45:46 UTC
README
Why more? Because I seem to use it in all my Laravel projects. And who doesn't want more Laravel? ;p
Highlights
compact()
Example for compact(), with say, a payment...
$user->update($payment->compact());
// is the same as
$user->update(['payment_id' => $payment->getKey()]);
// or if your field was `default_payment_id` instead of `payment_id`...
$user->update($payment->compact('default_payment');
unmorph($as = null)
The unmorph($as) function is similar to compact()...
$order->update($transaction->unmorph('charge'));
// is the same as
$order->update(['charge_id' => $transaction->getKey(), 'charge_type' => get_class($transaction)]);
BelongsToUser
How often do your models belong to User... a lot, right?
class Post extend Model
{
use BelongsToUser;
}
Usage
$post->user() // BelongsTo
$post->user // App\User
$post->isAccessibleBy($user) // boolean
Post::forUser($user) // Builder|Post
Post::forUsers($arr_or_col) // Builder|Post
Post::createForUser($user, [...]) // Post
And of course there is more included
The \More\Laravel\Traits\Model\Core namespace is reasonable for global usage.
The \More\Laravel\Traits\Model namespace is for the per model use cases.
Good Luck!
Composer
$ composer require dan/laravel-more dev-master
Implementation options
Do you have a base model? e.g. App\Model
Yes
- Add the traits you like to base model.
- Or extend \More\Laravel\Model
No
- Make a base model
\App\Modelthat extendsMore\Laravel\Modelor do à la carte, anduse \More\Laravel\Traits\Model\*as needed. - Or extend
\More\Laravel\Modelif you're really lazy. - Or use traits on specific models...blerg.
Contributors
License
MIT.