Last active
March 8, 2022 08:51
-
-
Save AlphaRomeoMike/c4aa421a74d60340e71b353ab8665ca2 to your computer and use it in GitHub Desktop.
Laravel Cron Factory and Seeder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Database\Factories; | |
use Illuminate\Database\Eloquent\Factories\Factory; | |
/** | |
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Bill> | |
*/ | |
class BillFactory extends Factory | |
{ | |
/** | |
* Define the model's default state. | |
* | |
* @return array<string, mixed> | |
*/ | |
public function definition() | |
{ | |
return [ | |
'name' => $this->faker->firstName(), | |
'user_id' => rand(1, 2), | |
'category_id' => rand(1, 10), | |
'subcategory_id' => rand(1, 10), | |
'amount' => rand(0.1, 250), | |
'paid' => rand(0, 1), | |
'due_date' => now()->addDays(rand(10, 30)), | |
]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Database\Seeders; | |
use App\Models\Bill; | |
use Illuminate\Database\Console\Seeds\WithoutModelEvents; | |
use Illuminate\Database\Seeder; | |
class BillSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
Bill::factory(10)->create(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Database\Seeders; | |
use Illuminate\Database\Console\Seeds\WithoutModelEvents; | |
use Illuminate\Database\Seeder; | |
class DatabaseSeeder extends Seeder | |
{ | |
/** | |
* Seed the application's database. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
// \App\Models\User::factory(10)->create(); | |
$this->call(BillSeeder::class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment