-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laravel 5.7 initializeTraits breaks models that override the boot method #25455
Comments
If you are overriding the If you check some example in the Laravel docs you will also notice Example: https://laravel.com/docs/5.7/eloquent#global-scopes (scroll little further to "Applying Global Scopes") Unless you are overriding the constructor the boot method will always be called:
|
I understand. However, this does break all apps migrating to 5.7 that don't override the I see three possible decision points for this issue:
|
To be clear, But for clarity, you are saying that if you do: class Entity extends \Illuminate\Database\Eloquent\Model
{
public static boot()
{
// some logic
}
} Instead of: class Entity extends \Illuminate\Database\Eloquent\Model
{
public static boot()
{
parent::boot();
// some logic
}
} it breaks any 5.7 application. Which I would say is very correct. Not calling |
Yes @stayallive that's what I meant. I'll close this issue in that case |
This was causing the error: Undefined index: App\Models\CustomField (View: /Users/snipe/Sites/snipe-it/snipe-it/resources/views/hardware/index.blade.php) and pointed to the Eloquent model library method: ``` protected function initializeTraits() { foreach (static::$traitInitializers[static::class] as $method) { $this->{$method}(); } } ``` Thanks to laravel/framework#25455 for the clue.
called parent::boot inside the boot method of ModelLock.php see: laravel/framework#25455
Description:
This PR assumes all models call the Model::boot static method. There may be some implementations where the parent boot method is not called. That results in an error Undefined index [class name] in the
initializeTraits
method in the following line:foreach (static::$traitInitializers[static::class] as $method) {
I'm not sure if it's expected that all models always call the Model::boot method but Laravel 5.7 certainly will break apps that don't do that.
Steps To Reproduce:
Override the
public static function boot
method in any model in Laravel and do not call theparent::boot
method. Probably can check with the User model and visit any page - the following error will pop up:Undefined index App\User
The text was updated successfully, but these errors were encountered: