Creation of documents number to support ISO for your Eloquent models in Laravel framework
-
Install the package via Composer.
$ composer require baraear/eloquent-documentable
-
Register the service provider in
config/app.php
./* * Package Service Providers... */ Baraear\Documentable\DocumentableServiceProvider::class,
-
Update your database column of the table that what you want to use documentable.
/** * Run the migrations. * * @return void */ public function up() { Schema::table('invoices', function (Blueprint $table) { $table->string('documentable'); }); }
-
Update your eloquent models.
use Baraear\Documentable\Documentable; class Invoice extends Model { use Documentable; /** * Return the documentable configuration array for this model. * * @return array */ public function documentable() { return [ 'prefix' => 'IV', 'length' => 4 ]; } }
NOTE: By default if not set the length is will equal to 4.
When you create new invoice the data will like this.
+----+--------------+---------------------+---------------------+
| id | documentable | created_at | updated_at |
+----+--------------+---------------------+---------------------+
| 1 | IV1801060001 | 2018-01-06 13:06:51 | 2018-01-06 13:06:51 |
+----+--------------+---------------------+---------------------+
1 row in set (0.00 sec)