Call to undefined method App\Models\Appointment::name()
Hi all,
I am trying to create a new appointment but I am getting the error that the method
This is my source code:
Model
AppointmentResource
I am trying to create a new appointment but I am getting the error that the method
name()name() is undefined. I don't know where this is comming from.This is my source code:
Model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Appointment extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'phone',
'status',
'date',
'time',
'message',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'date' => 'date',
'time' => 'time',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* Get the services for the appointment.
*
* @return BelongsToMany
*/
public function services(): BelongsToMany
{
return $this->belongsToMany(Service::class, 'appointment_service');
}
}<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Appointment extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'phone',
'status',
'date',
'time',
'message',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'date' => 'date',
'time' => 'time',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* Get the services for the appointment.
*
* @return BelongsToMany
*/
public function services(): BelongsToMany
{
return $this->belongsToMany(Service::class, 'appointment_service');
}
}AppointmentResource
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Fieldset::make()
->label(label: __(key: 'Client Details'))
->schema([
Forms\Components\TextInput::make(name: 'name')
->autofocus()
->required()
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Name')),
Forms\Components\TextInput::make(name: 'email')
->required()
->type(type: 'email')
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Email')),
Forms\Components\TextInput::make(name: 'phone')
->required()
->type(type: 'tel')
->columnSpan(span: 2)
->placeholder(placeholder: __(key: 'Phone')),
])->columns(),
Forms\Components\Fieldset::make()
->label(label: __(key: 'Appointment Details'))
->schema([
Forms\Components\Datepicker::make(name: 'date')
->required()
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Date')),
Forms\Components\Timepicker::make(name: 'time')
->required()
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Time')),
Forms\Components\CheckboxList::make(name: 'services')
->required()
->relationship(name: 'name', titleAttribute: 'name')
->options(Service::all()->pluck('name', 'id')->toArray())
->columnSpan(span: 2)
])->columns(),
]);
}public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Fieldset::make()
->label(label: __(key: 'Client Details'))
->schema([
Forms\Components\TextInput::make(name: 'name')
->autofocus()
->required()
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Name')),
Forms\Components\TextInput::make(name: 'email')
->required()
->type(type: 'email')
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Email')),
Forms\Components\TextInput::make(name: 'phone')
->required()
->type(type: 'tel')
->columnSpan(span: 2)
->placeholder(placeholder: __(key: 'Phone')),
])->columns(),
Forms\Components\Fieldset::make()
->label(label: __(key: 'Appointment Details'))
->schema([
Forms\Components\Datepicker::make(name: 'date')
->required()
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Date')),
Forms\Components\Timepicker::make(name: 'time')
->required()
->columnSpan(span: 1)
->placeholder(placeholder: __(key: 'Time')),
Forms\Components\CheckboxList::make(name: 'services')
->required()
->relationship(name: 'name', titleAttribute: 'name')
->options(Service::all()->pluck('name', 'id')->toArray())
->columnSpan(span: 2)
])->columns(),
]);
}Solution
also it should be
->relationship(name: 'services', titleAttribute: 'name')->relationship(name: 'services', titleAttribute: 'name')