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

Neeraj1005's avatar

BadMethodCallException Call to undefined method App\BookingService::bookevents()

can anyone tells me where did I make a mistakes. I tried but it gives me an error.

this is my route

Route::get('bookings/{bookservice:service_name}/event/{bookevent:event_name}','BookingHomePageController@create')->name('event.create');

this is my method

public function create(BookingService $bookservice , BookingEvent $bookevent)
    {
        // $events = BookingEvent::get();
        // dd($events->id);
        // if (request('bookevent')) {
        //     $events = BookingEvent::get();
        //     dd($events->event_name);
        // }
        return view('bookings.booking_form', compact('bookservice', 'bookevent'));
    }

this is model1

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BookingService extends Model
{
    use SoftDeletes;
    /**
     * @var string
    */
    protected $table = 'booking_services';

    /**
     * @var string
    */
    protected $primaryKey = 'id';

    protected $appends = [
        'name',
    ];

    /**
     * @var array
    */
    protected $fillable = ['service_name'];

    public function booking_events() {
        return $this->hasMany( BookingEvent::class );
    }

    public function getNameAttribute() {

        return lcfirst($this->service_name);
     }
}

this is model2

<?php

namespace App;

use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BookingEvent extends Model
{
    use SoftDeletes;
    /**
     * @var string
    */
    protected $table = 'booking_events';

    /**
     * @var string
    */
    protected $primaryKey = 'id';

    protected $with = ['booking_service'];

    // protected $withCount = ['booking_service'];

    /**
     * @var array
    */
    protected $fillable = [
        'event_name',
        'user_id',
        'booking_service_id',
        'duration',
        'price',
        'event_start',
        'event_end',
        'event_description',
    ];

    protected $appends = [
        'short_description',
    ];
    /**
     * Get the event based on the booking services.
     */
    public function booking_service()
    {
        return $this->belongsTo( BookingService::class );
    }

    public function getDurationAttribute($value)
    {
        return $value . " Hours";
    }

    public function user()
    {
        return $this->belongsTo( User::class );
    }

    public function getShortDescriptionAttribute()
    {
        return Str::limit($this->event_description, 56, '...');
    }

    public function booking_customers()
    {
        return $this->belongsToMany( BookingCustomer::class );
    }
}

0 likes
3 replies
Sergiu17's avatar

Search in your project for bookevents, you call this method but it is not defined

1 like
Neeraj1005's avatar

@sergiu17 yes in route i have a bookevent route like this.

Route::resource('bookevents', 'BookingEventController');
Route::get('bookings/{bookservice:service_name}/event/{bookevent:event_name}','BookingHomePageController@create')->name('event.create');

what should be order for this? should I have the routes?

Sergiu17's avatar
Sergiu17
Best Answer
Level 60

It's not about the routes, it's inside controllers I guess you have something like

$bookservice->bookevents()
// or
BookingService::bookevents() 

and you don't have such a method in your Model.

The error tells you exactly: Call to undefined method App\BookingService::bookevents()

method - bookevents

class - BookingService.php (Model)

1 like

Please or to participate in this conversation.