Viewing file: UserSeeder.php (2.23 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace Database\Seeders;
use App\Models\User; use App\Models\UserPlan; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; // For bcrypt use Illuminate\Support\Carbon; use Spatie\Permission\Models\Role;
class UserSeeder extends Seeder { public function run() { $data = [ [ 'name' => 'Alex Johnson', 'email' => 'alex@gmail.com', 'password' => bcrypt('123456'), 'restaurant_id' => 2, 'type' => 'restaurant_owner', 'status' => 'approved', 'picture' => 'default_profile.png', 'email_verified_at' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), ], [ 'name' => 'Marteen Golf', 'email' => 'golf@gmail.com', 'password' => bcrypt('123456'), 'restaurant_id' => 3, 'type' => 'restaurant_owner', 'status' => 'approved', 'picture' => 'default_profile.png', 'email_verified_at' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), ], [ 'name' => 'Sophie Lane', 'email' => 'customer@gmail.com', 'password' => bcrypt('123456'), 'restaurant_id' => null, 'type' => 'customer', 'status' => 'approved', 'picture' => 'default_profile.png', 'email_verified_at' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), ], ];
User::insert($data);
$owners = User::where('type', 'restaurant_owner')->get(); $customer = User::where('type', 'customer')->first();
$ownerRole = Role::findOrCreate('restaurant_owner'); $customerRole = Role::findOrCreate('customer');
foreach ($owners as $owner) { $owner->assignRole($ownerRole); }
if ($customer) { $customer->assignRole($customerRole); } } }
|