These are a few console commands packaged together so they don't have to be recreated in new projects.
You can install the package via composer:
composer require invoate/console-commandsThe Pivot Make Command generates a migration for a pivot table. Table names can be passed in any order, the command will alphabetise them.
php artisan make:pivot table1 table2The table1 and table2 arguments can be existing Eloquent models or table names. Table names for Eloquent models will be automatically resolved.
php artisan make:pivot User TeamSchema::create('teams_users', function (Blueprint $table) {
$table->foreignId('team_id')->constrained();
$table->foreignId('user_id')->constrained();
//..
});By default the command generates foreign keys, this can be disabled with the --without-foreign-keys flag.
php artisan make:pivot User Team --without-foreign-keysSchema::create('teams_users', function (Blueprint $table) {
$table->integer('team_id');
$table->integer('user_id');
//..
});Timestamp columns are also generated by default, the --without-timestamps flag will disable these.
php artisan make:pivot User Team --without-timestampsAdditional columns can be created using the --columns flag, they must be formatted in the column_name:column_type format.
php artisan make:pivot User Team --columns string:role,timestamp:expires_atSchema::create('teams_users', function (Blueprint $table) {
//..
$table->string('role');
$table->timestamp('expires_at');
//..
});A pivot Eloquent model can be generated with the --with-model flag.
php artisan make:pivot User Team --model
# INFO Migration [database/migrations/2023_02_20_153354_create_teams_users_table.php] created successfully.
# INFO Model [app/Models/TeamUser.php] created successfully.Optionaly an id column can be generated using the --with-id flag. By default this will generate a $table->id() column, passing another Laravel supported column type with e.g. --id-type ulid will change this.
php artisan make:pivot User Team --with-id --id-type ulidSchema::create('teams_users', function (Blueprint $table) {
$table->ulid();
//..
});If you do not wish to generate any columns for the pivot table you can use the --without-columns flag.
php artisan make:pivot User Team --without-columnsSchema::create('teams_users', function (Blueprint $table) {
//
});The RefreshCommand is a simple wrapper for php artisan migrate:fresh --seed.
php artisan refreshcomposer testThe MIT License (MIT). Please see License File for more information.