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)
PHP 7.2 and laravel 5.8
You can install it via Composer by typing the following command:
composer require railken/eloquent-instance
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);
}
}