I have transactions table in laravel
Table have
Description, amount float value and type enum value credit,debit and created at creat ne larave app with this migration and seeder factory 10000 record
Assistant
To create a Laravel app with the migration and seeder for the transactions table, you can follow these steps:
Step 1: Create a new Laravel app using the composer command.
This will create a new migration file in the database/migrations directory.
Step 4: Open the created migration file and define the table structure.
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTransactionsTable extends Migration
{
public function up()
{
Schema::create('transactions', function (Blueprint $table) {
$table->id();
$table->string('description');
$table->float('amount');
$table->enum('type', ['credit', 'debit']);
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('transactions');
}
}
Step 5: Run the migration command to create the transactions table in the database.
php artisan migrate
Step 6: Create a seeder for generating sample data.
php artisan make:seeder TransactionsSeeder
Step 7: Open the created seeder file located in database/seeders directory.
use Illuminate\Database\Seeder;
use App\Models\Transaction;
class TransactionsSeeder extends Seeder
{
public function run()
{
Transaction::factory()->count(10000)->create();
}
}
Step 8: Open the database/seeders/DatabaseSeeder.php file and add the following line in the run() method.
$this->call(TransactionsSeeder::class);
Step 9: Run the seeder command to populate the transactions table.
php artisan db:seed
That's it! You have now created a Laravel app with the migration and seeder to generate 10,000 records in the transactions table.