diff --git a/.env.example b/.env.example index 886c504..28077b8 100644 --- a/.env.example +++ b/.env.example @@ -65,3 +65,6 @@ VITE_APP_NAME="${APP_NAME}" OPENAI_API_KEY= OPENAI_ORGANIZATION= + +ADMIN_EMAIL=test@test.com +ADMIN_PASSWORD=password diff --git a/README.md b/README.md index 3c27fa1..bc6ae0a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/database/seeders/AdminSeeder.php b/database/seeders/AdminSeeder.php index cfb379d..f13138b 100644 --- a/database/seeders/AdminSeeder.php +++ b/database/seeders/AdminSeeder.php @@ -2,6 +2,8 @@ namespace Database\Seeders; +use App\Actions\Jetstream\CreateTeam; +use App\Models\Team; use App\Models\User; use Illuminate\Database\Seeder; @@ -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', + ]); + } } }