larastan: Larastan doesn't detect a renameColumn name
- Larastan Version: v2.9.4
- Laravel Version: v10.48.7
- Level: 1
Description
In a migration, I create a column last_changed_at, and in a later migration I do a $table->renameColumn('last_changed_at', 'first_detection_at'). last_changed_at isn’t used anymore, but first_detection_at is.
But phpstan gives me an error:
Access to an undefined property App\Models\SiteCheck::$first_detection_at.
Only that property. All the others are detected OK. It seems the renameColumn() doesn’t work.
If I edit the migration and add in up():
// larastan
return;
\Schema::table('site_checks', function(Blueprint $table) {
$table->timestamp('first_detection_at');
});
Larastan gets it. But that’s too hacky, even for me.
If I add some debug in SchemaAggregator:
case 'renamecolumn':
dump($columnName, $secondArg->value);
and run phpstan with --debug, it seems Larastan does understand the renameColumn():
"last_changed_at" // vendor/larastan/larastan/src/Properties/SchemaAggregator.php:412
"first_detection_at" // vendor/larastan/larastan/src/Properties/SchemaAggregator.php:412
but it still doesn’t apply the change…?
Should I read the migrations as bootstrap files or something?
I’ll try to upgrade Laravel and Larastan to try the newest version. Same error with newest versions.
About this issue
- Original URL
- State: closed
- Created 2 months ago
- Comments: 16 (4 by maintainers)
Yes, level 1 doesn’t complain. Level 2 does. Alright, I’m really done here now 😆 Thanks guys.
Waaaaaaaaaaaaaaaait!!
Larastan doesn’t even think the original column
last_changed_atexists. And that totally makes sense, because I’m an idiot!An earlier migration created
last_changed_at, but not using Schema/Blueprint:Sorry for wasting your time guys. That was not mysterious at all.
Maybe
SchemaTable::renameColumn()could throw a warning or something 😆 so dumb people don’t get confused for days.Thanks for bearing with me. I’ll make better migrations in the future ❤️
There’s no
first_detection_atcolumn! Yet, in other places (outside$thiscontext), there’s no error for this property, so sometimes it does exist… Computers are weird.never triggers for
first_detection_at, so it doesn’t think it’s deleted after being renamed.I give up.
After this line you can put a
dd($this->tables)to see everything Larastan recognized.Hi,
We’d need more information. Or even better a small repository that can reproduce the issue. As you can see, we cannot reproduce it.