I am trying to create a common class for models, where I am passing the model instance to my separate parameter
class Custom
{
private $model;
public function getAll()
{
return $this->model->get();
}
public function setModel(Model $model)
{
$this->model=$model;
}
}
and my controller I have
$customModel=new Custom();
$customModel->setModel(Branch::class);
echo "<pre>";
print_r($customModel->getAll());
and also I tried
$response=$this->customDatatable->setModel(Branch::class)->getAll();
echo "<pre>";
print_r($response->toArray());
but I got the following Error
Argument 1 passed to App\Helpers\Custom::setModel() must be an instance of Illuminate\Database\Eloquent\Model, string given, called