hasOne query existence.
how do I query hasOne existence? What I want to achieve is, if the user has not register their company's contact, Add Company Contact will appear.
this is my attempt:
controller
$companyContact = Company::find($id)->companycontact()->get();
view
@if($companyContact->isEmpty())
<p><a href="#">Add Company Contact</a><p>
@endif
// App\Company.php
return contact()
{
return $this->hasOne(Contact::class);
}
// App\Http\Controllers\CompanyController.php
$company = Company::findOrFail($id);
// Your View
@if($company->contact)
<p><a href="#">Add Company Contact</a><p>
@endif
Please or to participate in this conversation.