Hi
I am having invoices and customers and users how can generete both
Customer Model:
public function invoices()
{
return $this->hasMany(Invoice::class);
}
Invoice Model:
public function customer()
{
return $this->belongsTo(Customer::class);
}
When I log in as the first user I can retreive the customer name with:
{{ $invoice->customer->name }}
but when I log in as the second I get:
Undefined property: Illuminate\Database\Eloquent\Collection::$customer
What is happenig here?
Btw I retrieve the invoices in the controller like so:
$invoices = Invoice::where('user_id',Auth::user()->id)->latest()->get();
any help would be greatly appreciated
Solved: in the db was a little corrupted There where invoices that did not belong to user customers or something like that. Found out by deleting all user 2 invoices and adding them correctly.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community