Try to search your question here, if you can't find : Ask Any Question Now ?

Call to a member function get() on null for a function in a model

HomeCategory: stackoverflowCall to a member function get() on null for a function in a model
Avatargaurav asked 4 months ago

I am trying to have a button of an employee show the text “Already booked” if the variable
count($bookingRequests) returns something and if nothing then show “Book Me’

I get the error above.

I have the following models and their relationships:

User.php and Bookings.php


public function bookings() {

        return $this->hasMany('AppModelsBookings');


public function BookingRequest()




public function user(){

    return $this->belongsTo('AppModelsUser');


The view mentioned above is Employeeblock.blade.php:

       <div class="row no-gutters mb-5 mb-lg-0" style="padding:10px">

                    <a href="#" class="btn btn-primary" data- 
                toggle="modal" data-target=“#bookingModal">Already Booked</a>


                    <a href="#" class="btn btn-primary" data- 
                      toggle="modal" data-target="#bookingModal">Book Me</a>



Which has data passed onto it by a controller SearchController:

In the following way:

           namespace AppHttpControllers;

      use DB;
      use Auth;
      use AppModelsEmployee;
      use AppModelsUser;
      use AppModelsBookings;
      use IlluminateHttpRequest;

      use GuzzleHttpClient;
      use Session;


        return view(‘search.results’) 

results.blade.php above has the following html:

    <div class="panel panel-default">
        <div class="panel-heading"><h3></h3></div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-12">

                            @foreach($Employees as $Employee)


1 Answers
Best Answer
AvatarMikhail answered 4 months ago
Your Answer

20 + 3 =

Popular Tags

WP Facebook Auto Publish Powered By :