Skip to content

Commit aa52199

Browse files
committed
README.md update
1 parent 76ef8d2 commit aa52199

File tree

2 files changed

+74
-47
lines changed

2 files changed

+74
-47
lines changed

README.md

+70-47
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
# #todo: description will be here
1+
# Package Summary
2+
This Laravel package provides a handy trait called HasOrder designed to simplify
3+
the management of ordered records in your Eloquent models. By applying this trait
4+
to your models, you introduce an 'order' attribute, allowing you to effortlessly
5+
handle the ordering of records within a given model.
26

37
[![Latest Version on Packagist](https://img.shields.io/packagist/v/yusufalper/laravel-order.svg?style=flat-square)](https://packagist.org/packages/yusufalper/laravel-order)
48
[![Total Downloads](https://img.shields.io/packagist/dt/yusufalper/laravel-order.svg?style=flat-square)](https://packagist.org/packages/yusufalper/laravel-order)
59

6-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
7-
8-
## Support us
9-
10-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-order.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-order)
11-
12-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
13-
14-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
15-
1610
## Installation
1711

1812
You can install the package via composer:
@@ -21,61 +15,90 @@ You can install the package via composer:
2115
composer require yusufalper/laravel-order
2216
```
2317

24-
You can publish and run the migrations with:
25-
26-
```bash
27-
php artisan vendor:publish --tag="laravel-order-migrations"
28-
php artisan migrate
29-
```
18+
## Usage
19+
1. Apply Trait:
20+
Simply apply the HasOrder trait to your Eloquent model.
21+
Ensure that your model's migration includes an 'order' column (integer and nullable)
22+
to support the ordering functionality.
3023

31-
You can publish the config file with:
24+
2. Optional Configuration:
25+
Optionally, you can define $orderUnificationAttributes (public array) within your model
26+
to fine-tune the ordering behavior according to your application's specific requirements.
27+
For example if you add 'user_id' attribute to $orderUnificationAttributes, then your
28+
ordering will be user_id based ordering.
3229

33-
```bash
34-
php artisan vendor:publish --tag="laravel-order-config"
35-
```
30+
3. Automatic Handling:
31+
The package takes care of automatic order adjustments during record creation,
32+
ensuring a seamless and organized ordering process.
3633

37-
This is the contents of the published config file:
34+
4. Effortless Update and Delete:
35+
The HasOrder trait also seamlessly handles updates and deletes, maintaining the correct order of records based on your defined criteria.
3836

37+
## Example Usage
3938
```php
40-
return [
41-
];
42-
```
39+
use Illuminate\Database\Eloquent\Model;
40+
use Alper\LaravelOrder\Traits\HasOrder;
41+
42+
class CompanyBranch extends Model
43+
{
44+
use HasOrder;
45+
46+
protected $fillable = [
47+
'order'
48+
'company_id'
49+
];
50+
51+
public array $orderUnificationAttributes = [
52+
'company_id'
53+
];
54+
}
4355

44-
Optionally, you can publish the views using
45-
46-
```bash
47-
php artisan vendor:publish --tag="laravel-order-views"
4856
```
4957

50-
## Usage
51-
58+
If you have multiple traits that each of which has a boot method,
59+
Then you should use like this:
5260
```php
53-
$laravelOrder = new Alper\LaravelOrder();
54-
echo $laravelOrder->echoPhrase('Hello, Alper!');
55-
```
56-
57-
## Testing
61+
use Illuminate\Database\Eloquent\Model;
62+
use Alper\LaravelOrder\Traits\HasOrder;
63+
64+
class CompanyBranch extends Model
65+
{
66+
use HasOrder {
67+
HasOrder::boot as bootHasOrderTrait;
68+
}
69+
use OtherTrait {
70+
OtherTrait::boot as bootOtherTraitTrait;
71+
}
72+
73+
public static function boot(): void
74+
{
75+
static::bootHasOrderTrait();
76+
static::bootOtherTraitTrait();
77+
}
78+
79+
protected $fillable = [
80+
'order'
81+
'company_id'
82+
];
83+
84+
public array $orderUnificationAttributes = [
85+
'company_id'
86+
];
87+
}
5888

59-
```bash
60-
composer test
6189
```
6290

91+
By integrating the HasOrder trait into your Laravel models,
92+
you streamline the process of managing ordered records,
93+
offering enhanced control and flexibility.
94+
6395
## Changelog
6496

6597
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
6698

67-
## Contributing
68-
69-
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
70-
71-
## Security Vulnerabilities
72-
73-
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
74-
7599
## Credits
76100

77101
- [Alper](https://github.com/yusufalper)
78-
- [All Contributors](../../contributors)
79102

80103
## License
81104

src/Traits/HasOrder.php

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use Illuminate\Support\Facades\DB;
88
use Throwable;
99

10+
/*
11+
* Requires 'order' (integer and nullable) attribute from Model Migration
12+
* Gets optional $orderUnificationAttributes property from Model Class.
13+
*/
1014
trait HasOrder
1115
{
1216
protected static function boot(): void

0 commit comments

Comments
 (0)