Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
L
laravel_training
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TTS Tran Viet Anh
laravel_training
Commits
241193f5
Commit
241193f5
authored
Nov 08, 2022
by
TTS Tran Viet Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
seeding database
parent
86316bdc
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
139 additions
and
1 deletion
+139
-1
PostCategoryFactory.php
database/factories/PostCategoryFactory.php
+25
-0
PostFactory.php
database/factories/PostFactory.php
+29
-0
ProductAttributeFactory.php
database/factories/ProductAttributeFactory.php
+24
-0
ProductCategoryFactory.php
database/factories/ProductCategoryFactory.php
+25
-0
ProductFactory.php
database/factories/ProductFactory.php
+28
-0
UserFactory.php
database/factories/UserFactory.php
+2
-0
DatabaseSeeder.php
database/seeders/DatabaseSeeder.php
+6
-1
No files found.
database/factories/PostCategoryFactory.php
0 → 100644
View file @
241193f5
<?php
namespace
Database\Factories
;
use
App\Models\PostCategory
;
use
Illuminate\Database\Eloquent\Factories\Factory
;
class
PostCategoryFactory
extends
Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public
function
definition
()
{
return
[
'name'
=>
$this
->
faker
->
sentence
(
1
),
'image'
=>
$this
->
faker
->
imageUrl
(
80
,
640
,
'Post category'
,
true
),
'parent_id'
=>
rand
(
0
,
1
)
?
null
:
rand
(
1
,
10
),
'status'
=>
PostCategory
::
STATUS_ENABLE
,
'ordering'
=>
rand
(
1
,
3
),
];
}
}
database/factories/PostFactory.php
0 → 100644
View file @
241193f5
<?php
namespace
Database\Factories
;
use
App\Models\Post
;
use
App\Models\PostCategory
;
use
App\Models\User
;
use
Illuminate\Database\Eloquent\Factories\Factory
;
class
PostFactory
extends
Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public
function
definition
()
{
return
[
'title'
=>
$this
->
faker
->
sentence
(),
'content'
=>
$this
->
faker
->
paragraph
(),
'image'
=>
$this
->
faker
->
imageUrl
(
640
,
480
,
'post'
,
true
),
'user_id'
=>
User
::
inRandomOrder
()
->
first
()
->
id
??
null
,
'post_category_id'
=>
PostCategory
::
inRandomOrder
()
->
first
()
->
id
??
null
,
'publish_date'
=>
$this
->
faker
->
date
(),
'status'
=>
Post
::
STATUS_PUBLISHED
,
];
}
}
database/factories/ProductAttributeFactory.php
0 → 100644
View file @
241193f5
<?php
namespace
Database\Factories
;
use
App\Models\Product
;
use
Illuminate\Database\Eloquent\Factories\Factory
;
class
ProductAttributeFactory
extends
Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public
function
definition
()
{
return
[
'size'
=>
$this
->
faker
->
randomElement
([
'S'
,
'M'
,
'L'
,
'XL'
]),
'color'
=>
$this
->
faker
->
safeColorName
(),
'quantity'
=>
$this
->
faker
->
numberBetween
(
0
,
100
),
'product_id'
=>
Product
::
inRandomOrder
()
->
first
()
->
id
??
null
,
];
}
}
database/factories/ProductCategoryFactory.php
0 → 100644
View file @
241193f5
<?php
namespace
Database\Factories
;
use
App\Models\ProductCategory
;
use
Illuminate\Database\Eloquent\Factories\Factory
;
class
ProductCategoryFactory
extends
Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public
function
definition
()
{
return
[
'name'
=>
$this
->
faker
->
sentence
(
1
),
'image'
=>
$this
->
faker
->
imageUrl
(
80
,
640
,
'product category'
,
true
),
'parent_id'
=>
rand
(
0
,
1
)
?
null
:
rand
(
1
,
10
),
'status'
=>
ProductCategory
::
STATUS_ENABLE
,
'ordering'
=>
rand
(
1
,
3
),
];
}
}
database/factories/ProductFactory.php
0 → 100644
View file @
241193f5
<?php
namespace
Database\Factories
;
use
App\Models\Product
;
use
App\Models\ProductCategory
;
use
Illuminate\Database\Eloquent\Factories\Factory
;
class
ProductFactory
extends
Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public
function
definition
()
{
return
[
'name'
=>
$this
->
faker
->
sentence
(
2
),
'image'
=>
$this
->
faker
->
imageUrl
(
480
,
640
,
'products'
,
true
),
'description'
=>
$this
->
faker
->
paragraph
(
2
),
'price'
=>
$this
->
faker
->
randomFloat
(
2
,
10
,
200
),
'product_category_id'
=>
ProductCategory
::
inRandomOrder
()
->
first
()
->
id
??
null
,
'stock'
=>
$this
->
faker
->
numberBetween
(
0
,
200
),
'status'
=>
Product
::
STATUS_ENABLE
,
];
}
}
database/factories/UserFactory.php
View file @
241193f5
...
...
@@ -17,6 +17,8 @@ public function definition()
return
[
'name'
=>
$this
->
faker
->
name
(),
'email'
=>
$this
->
faker
->
unique
()
->
safeEmail
(),
'phone'
=>
$this
->
faker
->
phoneNumber
(),
'address'
=>
$this
->
faker
->
address
(),
'email_verified_at'
=>
now
(),
'password'
=>
'$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'
,
// password
'remember_token'
=>
Str
::
random
(
10
),
...
...
database/seeders/DatabaseSeeder.php
View file @
241193f5
...
...
@@ -13,6 +13,11 @@ class DatabaseSeeder extends Seeder
*/
public
function
run
()
{
// \App\Models\User::factory(10)->create();
\App\Models\PostCategory
::
factory
(
5
)
->
create
();
\App\Models\ProductCategory
::
factory
(
5
)
->
create
();
\App\Models\User
::
factory
(
5
)
->
create
();
\App\Models\Post
::
factory
(
10
)
->
create
();
\App\Models\Product
::
factory
(
10
)
->
create
();
\App\Models\ProductAttribute
::
factory
(
50
)
->
create
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment