-1

I have Enums which I am using it in almost all files for migration. Important them one by one is lots of work every time. Is there a way I can modify the template for laravel migration command and add those imports at the start itself and also if possible, the common fields too.

below is not the answer to what I need. Majority of the part of the question is about Auto import the enums file, below is just the part for fields which I have asked but don't think can be accepted as answer as how to add import is missing in the first place.

Can one modify the templates created by artisan migrate command?

Example below: Default migration file header

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;


Code I expect for migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Enums\Role; // added by me
use App\Enums\Status; // added by me
princeoo7
  • 1,071
  • 3
  • 21
  • 44
  • Have a look at https://stackoverflow.com/questions/21810251/can-one-modify-the-templates-created-by-artisan-migrate-command – ya-cha Mar 20 '20 at 15:59
  • Yes I have look and thats just the field thing answer. If you read my question, its more of the imports I want in the migration file. – princeoo7 Mar 20 '20 at 16:44

1 Answers1

0

You can use PHP include: include(relative/path/to/fieldsarray.php) and that file will be an array of what you want with something like:

Migration File:

$table->enum('level', include(relative/path/to/fieldsarray.php));

Common File:

<?php

// Current File: relative/path/to/fieldsarray.php

return [
   'option1',
   'option2',
];
jeremykenedy
  • 4,150
  • 1
  • 17
  • 25
  • you gave the example for the fields I suppose. again not the answer I was looking at first. still thank you for your assistances though :) – princeoo7 Mar 22 '20 at 09:40