Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Hi,

If it hasOne('Hour'), why should it be an array ?

Last updated 2 years ago.
0

Yea, thought it would be the relationships.. Its messed up inside my head right now :D.

I want to output the all of the opening to closing hours of each shop, so I guess it should be many to many then?

Last updated 2 years ago.
0

One shop has "one" opening hours, so it is hasOne

But you don't have to loop over the hours, as it is just a row object. You can just do it: $listing->hours()->open_mon

Last updated 2 years ago.
0

I tried doing in my view:

{{ $listing->hours()->open_mon }} - {{ $listing->hours()->close_mon }}
{{ $listing->hours()->open_tue }} - {{ $listing->hours()->close_tue }}

But I get this:

Undefined property: Illuminate\Database\Eloquent\Relations\HasOne::$open_mon

In my show view i can loop over the relationship like this:

{{ $listing->hours->open_mon }} - {{ $listing->hours->close_mon }}
{{ $listing->hours->open_tue }} - {{ $listing->hours->close_tue }}

So im thinking there should be a way?

Last updated 2 years ago.
0

Anyone????

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Reached reached Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.