|
1 |
| -# LaravelDynamicModel |
| 1 | +# Laravel Dynamic Model |
2 | 2 |
|
3 |
| -[![Latest Version on Packagist][ico-version]][link-packagist] |
4 |
| -[![Total Downloads][ico-downloads]][link-downloads] |
5 |
| -[![Build Status][ico-travis]][link-travis] |
6 |
| -[![StyleCI][ico-styleci]][link-styleci] |
| 3 | +<p align="left"> |
| 4 | +<!--<a href="https://packagist.org/packages/sairahcaz/laravel-dynamic-model"><img src="https://img.shields.io/packagist/dt/sairahcaz/laravel-dynamic-model" alt="Total Downloads"></a>--> |
| 5 | +<a href="https://packagist.org/packages/sairahcaz/laravel-dynamic-model"><img src="https://img.shields.io/packagist/v/sairahcaz/laravel-dynamic-model" alt="Latest Stable Version"></a> |
| 6 | +<a href="https://packagist.org/packages/sairahcaz/laravel-dynamic-model"><img src="https://img.shields.io/packagist/l/sairahcaz/laravel-dynamic-model" alt="License"></a> |
| 7 | +</p> |
7 | 8 |
|
8 |
| -This is where your description should go. Take a look at [contributing.md](contributing.md) to see a to do list. |
| 9 | +## Introduction |
| 10 | + |
| 11 | +Laravel Dynamic Model provides you with a model which can handle multiple database tables. |
| 12 | +*Warning*: this is only a good approach if you really know what your doing and you have no other option! |
9 | 13 |
|
10 | 14 | ## Installation
|
11 | 15 |
|
12 |
| -Via Composer |
| 16 | +Dependencies |
| 17 | +This package depends on Doctrine/DBAL, so make sure you have it or install it. |
| 18 | + |
| 19 | +``` bash |
| 20 | +$ composer require doctrine/dbal |
| 21 | +``` |
| 22 | + |
| 23 | +Package |
13 | 24 |
|
14 | 25 | ``` bash
|
15 | 26 | $ composer require sairahcaz/laravel-dynamic-model
|
| 27 | +$ php artisan vendor:publish --provider="Sairahcaz\LaravelDynamicModel\DynamicModelServiceProvider" --tag="config" |
16 | 28 | ```
|
17 | 29 |
|
| 30 | + |
18 | 31 | ## Usage
|
19 | 32 |
|
| 33 | +### Lets create a dummy table: |
| 34 | + |
| 35 | +``` bash |
| 36 | +$ php artisan make:migration create_foo_table |
| 37 | +``` |
| 38 | + |
| 39 | +``` php |
| 40 | +Schema::create('foo', function (Blueprint $table) { |
| 41 | + $table->id(); |
| 42 | + $table->string('col1'); |
| 43 | + $table->integer('col2'); |
| 44 | + $table->timestamps(); |
| 45 | +}); |
| 46 | +``` |
| 47 | + |
| 48 | +### Lets use our Dynamic Model: |
| 49 | + |
| 50 | + |
| 51 | +``` php |
| 52 | +$foo = App::make(DynamicModel::class, ['table_name' => 'foo']); |
| 53 | + |
| 54 | +$foo->create([ |
| 55 | + 'col1' => 'asdf', |
| 56 | + 'col2' => 123 |
| 57 | +]); |
| 58 | + |
| 59 | +dd($foo->first()); |
| 60 | +``` |
| 61 | + |
| 62 | +Which gives us: |
| 63 | + |
| 64 | +``` |
| 65 | +^ Sairahcaz\LaravelDynamicModel\DynamicModel {#328 ▼ |
| 66 | + #connection: "mysql" |
| 67 | + #table: "foo" |
| 68 | + #primaryKey: "id" |
| 69 | + #keyType: "integer" |
| 70 | + +incrementing: true |
| 71 | + #with: [] |
| 72 | + #withCount: [] |
| 73 | + +preventsLazyLoading: false |
| 74 | + #perPage: 15 |
| 75 | + +exists: true |
| 76 | + +wasRecentlyCreated: false |
| 77 | + #escapeWhenCastingToString: false |
| 78 | + #attributes: array:5 [▼ |
| 79 | + "id" => 1 |
| 80 | + "col1" => "asdf" |
| 81 | + "col2" => 123 |
| 82 | + "created_at" => "2022-09-22 15:34:22" |
| 83 | + "updated_at" => "2022-09-22 15:34:22" |
| 84 | + ] |
| 85 | + #original: array:5 [▼ |
| 86 | + "id" => 1 |
| 87 | + "col1" => "asdf" |
| 88 | + "col2" => 123 |
| 89 | + "created_at" => "2022-09-22 15:34:22" |
| 90 | + "updated_at" => "2022-09-22 15:34:22" |
| 91 | + ] |
| 92 | + #changes: [] |
| 93 | + #casts: [] |
| 94 | + #classCastCache: [] |
| 95 | + #attributeCastCache: [] |
| 96 | + #dates: [] |
| 97 | + #dateFormat: null |
| 98 | + #appends: [] |
| 99 | + #dispatchesEvents: [] |
| 100 | + #observables: [] |
| 101 | + #relations: [] |
| 102 | + #touches: [] |
| 103 | + +timestamps: true |
| 104 | + #hidden: [] |
| 105 | + #visible: [] |
| 106 | + #fillable: [] |
| 107 | + #guarded: [] |
| 108 | + #routeKeyName: "id" |
| 109 | +} |
| 110 | +``` |
| 111 | + |
20 | 112 | ## Change log
|
21 | 113 |
|
22 | 114 | Please see the [changelog](changelog.md) for more information on what has changed recently.
|
|
0 commit comments