I have a very weird issue with exactly one of my models – the update method is always null.
Any update is not working with the error "Call to undefined method App\Models\Menu::udpate()"
When I execute
$menu = $team->menus()->create([
'name' => $name
]);
dd($menu->update);
I get null
When I execute dd($menu)
I get
AppModelsMenu {#1289
#connection: "mysql"
#table: "menus"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [
"id" => 2
"name" => "Test"
"template_position" => null
"team_id" => 1
"created_at" => "2024-12-09 10:03:00"
"updated_at" => "2024-12-09 10:03:00"
]
#original: array:6 [
"id" => 2
"name" => "Test"
"template_position" => null
"team_id" => 1
"created_at" => "2024-12-09 10:03:00"
"updated_at" => "2024-12-09 10:03:00"
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: array:2 [
0 => "name"
]
#guarded: array:1 [
0 => "*"
]
}
Which looks fine.
My model looks like
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentRelationsBelongsTo;
use IlluminateDatabaseEloquentRelationsBelongsToMany;
class Menu extends Model
{
use HasFactory;
protected $fillable = ['name', 'template_position'];
public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}
public function pages(): BelongsToMany
{
return $this->belongsToMany(Page::class, 'menu_page', 'menu_id', 'page_id');
}
}
``
2