I faced the same problem and I solved it by making a new CustomBlueprint class. I wrote a separate blog on this. Just go there and you find your answers. Here I just give an example of migration file which have commonFields() method to add common fields in a model
$schema = DB::connection()->getSchemaBuilder();
$schema->blueprintResolver(function ($table, $callback) {
return new CustomBlueprint($table, $callback);
});
$schema->create('roles', function (CustomBlueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->commonFields();
});
I created CustomBlueprint class which have that method.
namespace App\common;
use Illuminate\Database\Schema\Blueprint;
class CustomBlueprint extends Blueprint
{
public function commonFields()
{
$this->timestamp('created_at')->nullable();;
$this->unsignedBigInteger('created_by')->nullable();
$this->timestamp('updated_at')->nullable();;
$this->unsignedBigInteger('updated_by')->nullable();
$this->timestamp('deleted_at')->nullable();;
$this->unsignedBigInteger('deleted_by')->nullable();
$this->boolean('is_deleted')->default(0);
}
}
link : https://medium.com/@harshshah8996/custom-blueprint-in-laravel-model-a772997c2fa3