RelationTableStringToPivotClassRector
Changes the pivot table name of a many to many relation to the pivot model class.
This is not purely a naming change: the framework applies a pivot class given as the table as if using() had been called, so the relation's pivot instances gain the class's casts, accessors, $timestamps and $incrementing.
-$this->belongsToMany(Tag::class, 'post_tag');
+$this->belongsToMany(Tag::class, \App\Models\PostTag::class);
Configure your rector.php:
<?php
use RectorLaravel\Rector\ClassMethod\RelationTableStringToPivotClassRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
RelationTableStringToPivotClassRector::class,
]);
PACKAGE:
laravel/framework >=8.0