I am new to laravel. I want to override construct method in my model, however, when I try to use the construct method inside my model, it returns an error saying Call to undefined method Illuminate\Database\Query\Builder::construct()
The purpose of using __construct
method is that I want to use DB table dynamically.
What is the problem? How could avoid this error?
Model
class Custom extends Model
{
protected $guarded = ['id', 'ct'];
const UPDATED_AT = null;
const CREATED_AT = 'ct';
public function __construct(string $tableName = null, array $attributes = []) {
$this->setTable($tableName);
parent::construct($attributes);
}
}
Controller
$custom = new Custom($tableName);
$result = $custom->create($data);
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2q9jBUR
via IFTTT
Aucun commentaire:
Enregistrer un commentaire