Category: Projects
Topic: Mini Ecommerce
Created: 3 years ago
// artisan command for migration, factory and seeder file
php artisan make:model Profile -mfs
// migration file
public function up()
{
Schema::create('profiles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('sequence');
$table->timestamps();
});
}
// ProfileFactory.php file
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProfileFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
private static $order = 1;
public function definition()
{
return [
'name' => $this->faker->text(50),
'sequence' => self::$order++
];
}
}
// ProfileSeeder.php file
namespace Database\Seeders;
use App\Models\Profile;
use Illuminate\Database\Seeder;
class ProfileSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
Profile::factory(10)->create();
}
}