title: Laravel One to Many Relationship not working
body: <p>I am doing my assignment for a hotel booking system. I have a table named bookings and another table room. I did a one to many relations between them I want to return the room name to the home view but it is always showing Trying to get property of non-object. This is my code.
  BOOKING Controllerclass GuestBookingController extends Controller</p>
  
  <pre><code>public function new()
  {
      $rooms = Room::all();
      $guests = Guest::all();
      return view('guestbookings.new', compact('rooms','guests'));
  }
  
  public function store(Request $request)
  {
      $validatedData = $request-&gt;validate([
          'checkin_dtime' =&gt; 'required',
          'checkout_dtime' =&gt; 'required',
          'id_number' =&gt; 'required|unique:guests',
          'mobile' =&gt; 'required',
           ]);
  
      $result = Booking::where('checkin_dtime', '&lt;=',$request-&gt;checkin_dtime)-&gt;where('checkout_dtime', '&gt;=',$request-&gt;checkout_dtime)-&gt;where('room_id',$request-&gt;room_id)-&gt;first();
     if(!$result){
     $bookings = new Booking;
     $bookings-&gt;checkin_dtime = $request-&gt;input('checkin_dtime');
     $bookings-&gt;checkout_dtime = $request-&gt;input('checkout_dtime');
     $bookings-&gt;user_id = auth()-&gt;user()-&gt;id;
     $bookings-&gt;save();
     $guests = new Guest;
     $guests-&gt;id_number = $request-&gt;input('id_number');
     $guests-&gt;mobile = $request-&gt;input('mobile');
     $guests-&gt;save;
  
  }
    return redirect('home');
  </code></pre>
  
  <p>Home view</p>
  
  <pre><code> &lt;table class="table table-striped"&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                            &lt;td&gt;ID&lt;/td&gt;
                            &lt;td&gt;Room Name&lt;/td&gt;
                            &lt;td&gt;Check-In&lt;/td&gt;
                            &lt;td&gt;Check-Out&lt;/td&gt;
                            &lt;td&gt;Status&lt;/td&gt;
                            &lt;td&gt;Action&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                          @foreach($bookings as $booking)
                          &lt;tr&gt;
                              &lt;td&gt;{{$booking['id']}}&lt;/td&gt;
  
                              &lt;td&gt;{{$booking-&gt;room-&gt;room_name}}&lt;/td&gt;
  
                              &lt;td&gt;{{$booking['checkin_dtime']}}&lt;/td&gt;
                              &lt;td&gt;{{$booking['checkout_dtime']}}&lt;/td&gt;
                              &lt;td&gt;
  </code></pre>
  
  <p>Booking Model</p>
  
  <pre><code> public function room()
  {
      return $this-&gt;belongsTo(Room::class, 'room_id');
  }
  public function user(){
      return $this-&gt;belongsTo(User::class);
  }
  </code></pre>