Skip to content

Commit

Permalink
Add usage notes
Browse files Browse the repository at this point in the history
  • Loading branch information
relliv committed Apr 9, 2023
1 parent 8fa01ec commit 38a6771
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![License][badge_license]][link_license]

## 📂 About
Useful model support traits...
Useful eloquent model support traits.

## 📦 Installation

Expand All @@ -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)**.
Expand Down

0 comments on commit 38a6771

Please sign in to comment.