Best laravel framework open-source packages.

Eloquent instance

A simple trait that enables the use of instance of Model in your relationships
Updated 3 years ago

Eloquent Instance

Actions Status

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 by typing the following command:

composer require railken/eloquent-instance

Usage

Simple include Railken\EloquentInstance\HasRelationships in your model and start using

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);
    }
}
Tags eloquent