In my Contact
model, I’m trying to type hint a service class:
use AppServicesContactService;
class Contact extends Model
{
/**
* @var AppServicesContactService
*/
protected $contactService;
public function __construct(ContactService $contactService)
{
$this->contactService = $contactService;
}
}
use AppServicesCRMCRMService;
class ContactService
{
public function __construct(protected CRMService $crmService)
{}
}
I’m getting this error:
Too few arguments to function AppModelsContact::__construct(), 0 passed in
The error happens when I call $dealer->contacts
public function contacts()
{
return $this->hasMany(AppModelsContact::class, 'dealer_id');
}
I thought the $contactService should be injected automatically and I shouldn’t be including it manually. What am I missing?
2
Answers
Based on the comments and answers, I ended up changing my Contact's model constructor to this and it's working great:
Thanks!
Try this in
Dealer
class