https://github.com/railken/eloquent-instance
A simple trait that enables the use of instance of Model in your relationships
https://github.com/railken/eloquent-instance
dynamic eloquent instance laravel relationships
Last synced: about 2 months ago
JSON representation
A simple trait that enables the use of instance of Model in your relationships
- Host: GitHub
- URL: https://github.com/railken/eloquent-instance
- Owner: railken
- License: mit
- Created: 2020-02-17T12:19:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-27T18:40:58.000Z (about 1 year ago)
- Last Synced: 2024-07-11T03:12:11.117Z (10 months ago)
- Topics: dynamic, eloquent, instance, laravel, relationships
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Eloquent Instance
[](https://github.com/railken/eloquent-instance/actions)
A simple trait that enables the use of instance of `Model` in your relationships. Why? Because otherwise it would be impossible to relate two models that doesn't exist in the code, but only as instances (e.g. stored in db)
## Requirements
PHP 7.2 and laravel 5.8
## Installation
You can install it via [Composer](https://getcomposer.org/) by typing the following command:
```bash
composer require railken/eloquent-instance
```## Usage
Simple include `Railken\EloquentInstance\HasRelationships` in your model and start using
```php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Railken\EloquentInstance\HasRelationships;class Author extends Model
{
use HasRelationships;
public function books()
{
$book = new Book();
$book->setTable('book_custom');return $this->hasMany($book);
}
}
```