Search in your project for bookevents, you call this method but it is not defined
Oct 6, 2020
3
Level 9
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 );
}
}
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.