Skip to content

Commit 745c057

Browse files
committed
Setup factories
1 parent f29e333 commit 745c057

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use App\Models\Category;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
use Illuminate\Support\Str;
8+
9+
class CategoryFactory extends Factory
10+
{
11+
/**
12+
* The name of the factory's corresponding model.
13+
*
14+
* @var string
15+
*/
16+
protected $model = Category::class;
17+
18+
/**
19+
* Define the model's default state.
20+
*
21+
* @return array
22+
*/
23+
public function definition()
24+
{
25+
$name = $this->faker->jobTitle;
26+
$nameArr = explode(' ', $name);
27+
28+
$name = trim($nameArr[0]);
29+
30+
return [
31+
'name' => $name,
32+
'slug' => Str::slug($name),
33+
];
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use App\Models\Product;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class ProductFactory extends Factory
9+
{
10+
/**
11+
* The name of the factory's corresponding model.
12+
*
13+
* @var string
14+
*/
15+
protected $model = Product::class;
16+
17+
/**
18+
* Define the model's default state.
19+
*
20+
* @return array
21+
*/
22+
public function definition()
23+
{
24+
return [
25+
//
26+
];
27+
}
28+
}

database/factories/UserFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function definition()
3030
'address' => $this->faker->address,
3131
'city' => $this->faker->city,
3232
'state' => $this->faker->state,
33-
'zip_code' => $this->faker->postcode
33+
'zipcode' => $this->faker->postcode
3434
];
3535
}
3636
}

0 commit comments

Comments
 (0)