railken/eloquent-instance

v2.0.0 2024-03-27 18:39 UTC

This package is auto-updated.

Last update: 2024-03-27 18:41:01 UTC


README

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