Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

screwtape_mk's avatar

Argument 1 passed to App\Models\User::BookingRequest() must be an instance of App\Models\userBookings, none given, called in ../laravel/app/Http/Controllers/SearchController.php on line 41 and defined

line 41 in searchController:

$bookingRequests=Auth::user()->BookingRequest();

User.php (Model):


    public function bookings() {
        
            return $this->hasMany('App\Models\Bookings');
    
    }   


    public function BookingRequest(userBookings $userBookings)
    
    {
        return (bool)$this->bookings()->where('email',$userBookings->email)
                                ->count();
                                
                                
                                
    
    }

The view:

@if(Auth::user()->BookingRequest($Userbookings))
                        <a href="#" class="btn btn-primary" data-toggle="modal" data-        
                            target="#bookingModal">Show Number</a>
@else
                
                        <a href="#" class="btn btn-primary" data-toggle="modal" data- 
                           target="#bookingModal">Book Me</a>
                        
@endif

Hope this is enough detail
0 likes
11 replies
tykus's avatar

Well clearly enough you are not giving an instance of userBookings here

$bookingRequests=Auth::user()->BookingRequest();
screwtape_mk's avatar

im new to laravel and trying to follow a tutorial so not sure exactly how would i do that

Cronix's avatar
$bookingRequests=Auth::user()->BookingRequest();

Look at the BookingRequest() method definition you defined. It requires an instance of the userBookings class to be passed to it.

public function BookingRequest(userBookings $userBookings)

You're not passing anything to it at all, hence the error message.

Cronix's avatar

im new to laravel and trying to follow a tutorial so not sure exactly how would i do that

It's not a method you would directly/manually call. That's really for a request coming directly from a route sending all of the form data (which gets processed through the userBookings request class you defined).

screwtape_mk's avatar

its possible that the tutorial which has the the same

$bookingRequests=Auth::user()->BookingRequest() 

is a little simpler for the specific case im trying build for. in the tutorial the BookingRequest is defined within the user.php model as:


    public function BookingRequest(User $user)
    
    {
        return (bool)$this->bookings()->where('email',$user->email)
                                ->count();
                                
    }
Cronix's avatar

You'd get the same problem if you tried to directly use

$bookingRequests=Auth::user()->BookingRequest();

because in your new example, you'd be required to pass an instance of User to BookingRequest().

public function BookingRequest(User $user) // requires a User instance to be passed
public function BookingRequest(userBookings $userBookings) // requires a userBookings instance to be passed
// nothing at all is being passed to BookingRequest, which is required by definition
$bookingRequests=Auth::user()->BookingRequest();
screwtape_mk's avatar

Ok i have tried to approach this in a different way. The ultimate goal is to have a particular button showing 'number ' if a searched employee has been booked already by the Authenticated user Or show ''Book Me" if that employee has not been booked.

I have altered BookingRequest to:

    public function BookingRequest($EmployeeNumber)
    
    {
    
        return $this->bookings()->where('booking_status','=','confirmed')
                                ->OrWhere('Employee_Phone','=',$EmployeeNumber)
                                ->get();

    }

I now get this error

Call to undefined method Illuminate\Database\Eloquent\Collection::getEmployeeMobile()

when i :

dd($Employees->getEmployeeMobile());

in the SearchController:

<?php 
namespace App\Http\Controllers;

use DB;
use Auth;
use App\Models\Employee;
use App\Models\User;
use App\Models\Bookings;

use Illuminate\Http\Request;

use GuzzleHttp\Client;
use Session;



class SearchController extends Controller {

    public function getResults(Request $request)
    {
    
        $query1=implode("",$request->input('EmpService'));
        $query2=implode("",$request->input('AccCity'));
        
        
        $token=$request->input('g-recaptcha-response');
        
        
        if(!$query1){
            return redirect()->route('home');
        }
        
        $Employees=Employee::where(DB::raw('EmployeeService'),'LIKE',"%{$query1}%")
                    ->where('AccentCity','LIKE',"%{$query2}%")
                    ->get();
        
        
        dd($Employees->getEmployeeMobile());
screwtape_mk's avatar

I have an Employee model:

    public function getEmployeeMobile()
    
        {
            if ($this->phone){
            
            return "{$this->phone}";
            }
            
            return null;
        
        }
    
    ```
Cronix's avatar
Cronix
Best Answer
Level 67

Yes, because $Employees is a collection, and not a single instance, so there is no $Employees->phone property. It might be a collection (array) containing a single model, but it's still a collection and not a single model. You'd have to use $Employees->first()->phone to grab the phone property from the first model instance in the collection and access the phone property on it, or loop through the collection of $Employees or something.

Do a dd($Employees); after you query it and check the output. It's an array of result(s). Not a single class with properties.

dd($Employees->getEmployeeMobile());

That would only work if $Employees is an instance of a single model instance. It's not.

Please or to participate in this conversation.