Hi,
My project has lots of model files which are mostly all the same, with exception of a couple. I had a little idea to create a generic model for any which don't have relationships and are basic. I am therefore trying to pass a $table name parameter into the model and hoping that it would all work itself out in the same way if you change the protected $table inside the model itself, but it seems to be having an issue.
I feel i am close, but clearly missing something.
Any help much appriciated on how this could be achieved.
Too few arguments to function App\Models\Crud::__construct(), 0 passed in
Model
Crud.php
class Crud extends Model
{
use HasFactory;
protected $table; // this works if i hardcode this to a value in the model directly
protected $guarded = [];
public function __construct($table)
{
$this->table = $table;
}
}
PageController which extends CRUDController (below)
PageController
class PageController extends CRUDController
{
protected $model;
/*****************************
** CONSTRUCTOR
*****************************/
public function __construct()
{
$this->model = new Crud('pages'); // this is the table name parameter
}
}
CrudController
CrudController
class CrudController extends Controller {
protected $model;
protected $fields;
/*****************************
** INDEX
*****************************/
public function index()
{
$result = $this->model::all(); // should be get maybe?
$data = array(
'result' => $result
);
return view("index")->with($data);
}
}