-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from msoares94/refactoring/migration
Refactoring migration e seeder
- Loading branch information
Showing
4 changed files
with
79 additions
and
21 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,7 @@ | |
|
||
namespace Database\Seeders; | ||
|
||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; | ||
use Illuminate\Database\Seeder; | ||
use Modules\Auth\Models\User; | ||
use Modules\Auth\Support\Role; | ||
|
||
class DatabaseSeeder extends Seeder | ||
{ | ||
|
@@ -16,11 +13,8 @@ class DatabaseSeeder extends Seeder | |
*/ | ||
public function run(): void | ||
{ | ||
User::query()->create([ | ||
'name' => 'Admin', | ||
'email' => '[email protected]', | ||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password | ||
'role' => Role::ADMIN->value, | ||
$this->call([ | ||
UserSeeder::class, | ||
]); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Seeders; | ||
|
||
use Illuminate\Database\Seeder; | ||
use Illuminate\Support\Facades\Hash; | ||
use Modules\Auth\Models\User; | ||
use Modules\Auth\Support\Role; | ||
|
||
class UserSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
*/ | ||
public function run(): void | ||
{ | ||
$user = User::query() | ||
->where('email', '[email protected]') | ||
->first(); | ||
|
||
if (! $user) { | ||
User::query()->create([ | ||
'email' => '[email protected]', | ||
'name' => 'Admin', | ||
'password' => Hash::make('password'), | ||
'role' => Role::ADMIN->value, | ||
]); | ||
|
||
return; | ||
} | ||
|
||
$user->update([ | ||
'name' => 'Admin', | ||
'password' => Hash::make('password'), | ||
'role' => Role::ADMIN->value, | ||
]); | ||
} | ||
} |
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