From 38a6771ecb9597526d6e19f433f8ec0430971077 Mon Sep 17 00:00:00 2001 From: Egoist Date: Sun, 9 Apr 2023 19:39:11 +0300 Subject: [PATCH] Add usage notes --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3869efb..9baa320 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![License][badge_license]][link_license] ## ๐Ÿ“‚ About -Useful model support traits... +Useful eloquent model support traits. ## ๐Ÿ“ฆ Installation @@ -24,6 +24,58 @@ composer require laravel-ready/model-support php artisan vendor:publish --tag=model-support-config ``` +## ๐Ÿ“ Usage + +### Sluggable + +This trait allows you to generate a slug from a string. When you create a new model, the slug will be generated automatically. If you change the title, the slug will also be updated. See [bootSluggable()](src/Traits/Sluggable.php#L10) method for more details. + +```php + +use LaravelReady\ModelSupport\Traits\Sluggable; +... + +$model->slug('any-string'); // will return $query->where('slug', $slug); +$model->slugLike('any-string'); // will return $query->where('slug', 'like', $slug); +$model->slugNot('any-string'); // will return $query->where('slug', '!=', $slug); +$model->slugNotLike('any-string'); // will return $query->where('slug', 'not like', $slug); +$model->slugIn(['any-string', 'any-string']); // will return $query->whereIn('slug', $slug); +$model->slugNotIn(['any-string', 'any-string']); // will return $query->whereNotIn('slug', $slug); + +``` + +### ParentChild + +This trait allows you to get all children of the model. It's only supports self-referencing models. + +```php + +use LaravelReady\ModelSupport\Traits\Sluggable; +... + +$model->parent(); // will return parent model +$model->children(); // will return children models +$model->allChildren(); // will return all children models +$model->allChildrenIds(); // will return all children ids +$model->recursiveParentAndChildren(); // will return all parent and children models + +``` + +### HasActive + +This trait allows you to get active/inactive status models. + +```php + +use LaravelReady\ModelSupport\Traits\Sluggable; +... + +$model->status(true|false); // will return $query->where('active', $status); +$model->active(); // will return $query->where('active', true); +$model->inactive(); // will return $query->where('active', false); + +``` + ## โš“Credits - This project was generated by the **[packager](https://github.com/laravel-ready/packager)**.