Here is modified sample. Used the default models when opening a new Laravel project:
app/Models/AbstractModels/AbstractSampleEntity.php:
<?php
/**
* Model object generated by: Skipper (http://www.skipper18.com)
* Do not modify this file manually.
*/
namespace App\Models\AbstractModels;
namespace App\Models;
abstract class AbstractSampleEntity extends AbstractBaseModel
{
}
Here you can see instead of using the Eloquent Model, we use a new AbstractBaseModel.
app/Models/AbstractBaseModel.php:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
abstract class AbstractBaseModel extends Model
{
/**
* The name of the "created at" column.
*
* @var string
*/
const CREATED_AT = 'created';
/**
* The name of the "updated at" column.
*
* @var string
*/
const UPDATED_AT = 'modified';
/**
* The table associated with the model.
*
* @var string
*/
protected $connection = 'my_custom_database_override';
}
This is now a global basemodel, but I would have liked that you . could have one per module, but you should be able to set this as property somehow.
Do you see the benefit of this? I have 100 Models imported from a second database. I do not want my laravel app to have its base tables in this database so I have 2 connections. This works fine, but I have to add the $connection varialbe manually on all models.. this could easily be added by generator.