I am new to laravel. I want to change table name to given string in the constructor in model. The code below is what I tried, but it seems not working.
Any suggestion or advice would be appreciated.
Thank you
Model
class Custom extends Model
{
protected $guarded = ['id', 'ct'];
const UPDATED_AT = null;
const CREATED_AT = 'ct';
public function __construct(array $attributes = [], string $tableName = null) {
parent::__construct($attributes);
$this->setTable($tableName);
}
}
Controller
$tableName = 'some string';
$custom = new Custom($tableName);
$result = $custom->create($data);
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2Ewt3EG
via IFTTT
Aucun commentaire:
Enregistrer un commentaire