Skip to content

Commit

Permalink
add better seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Oct 9, 2024
1 parent 6a1eddb commit 6f09334
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ VITE_APP_NAME="${APP_NAME}"

OPENAI_API_KEY=
OPENAI_ORGANIZATION=

ADMIN_EMAIL=[email protected]
ADMIN_PASSWORD=password
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@
This is the code used in the "PHP and LLMs" book long with [https://github.com/alnutile/php-llms](https://github.com/alnutile/php-llms)


## Setup

Should setup like a normal Laravel project

but a few things to consider:

### Database
cp you .env.example to .env and fill in the DB_ variables

but keep in mind you have to make the Postgres db ahead of time
Laravel will not create the db for you

Use HERD or DBNgine and all will go well for Postgres

### Seed Admin

cp you .env.example to .env and fill in the ADMIN_EMAIL and ADMIN_PASSWORD

```bash
php artisan db:seed --class=AdminSeeder
```

## Learn more at

* 👉🏻 Buy the book "PHP and LLMs - the practical guide" https://bit.ly/php_llms
Expand Down
17 changes: 14 additions & 3 deletions database/seeders/AdminSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Database\Seeders;

use App\Actions\Jetstream\CreateTeam;
use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Seeder;

Expand All @@ -12,10 +14,19 @@ class AdminSeeder extends Seeder
*/
public function run(): void
{
$user = User::create([
'name' => 'Alfred',
$user = User::updateOrCreate([
'email' => env('ADMIN_EMAIL'),
'password' => bcrypt(env('ADMIN_PASSWORD'))]);
],
[
'password' => bcrypt(env('ADMIN_PASSWORD')),
'name' => 'Admin',
]);

if (! Team::where('name', 'Admin Team')->exists()) {
(new CreateTeam)->create($user, [
'name' => 'Admin Team',
]);
}

}
}

0 comments on commit 6f09334

Please sign in to comment.