dan / laravel-more
More for your Laravel projects.
Installs: 18 118
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 0
Type:project
Requires
- php: >=7.0
- illuminate/database: ^5.5|^6.0|^7.0|^8.0
- illuminate/support: ^5.5|^6.0|^7.0|^8.0
- dev-master
- v0.3.1
- v0.3
- v0.2.17
- v0.2.16
- v0.2.14
- v0.2.13
- 0.2.12
- v0.2.11
- v0.2.10
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.0
- v0.1.0
- v0.0.19
- v0.0.18
- v0.0.17
- v0.0.16
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- 0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-enhancement/belongs-to-parent-always-return-a-model
This package is auto-updated.
Last update: 2024-10-28 10:02:07 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\Model
that extendsMore\Laravel\Model
or do à la carte, anduse \More\Laravel\Traits\Model\*
as needed. - Or extend
\More\Laravel\Model
if you're really lazy. - Or use traits on specific models...blerg.
Contributors
License
MIT.