auth with session

This commit is contained in:
2025-04-28 16:32:12 +03:30
parent c966f38236
commit fb750a0dc8
23 changed files with 900 additions and 81 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\City>
*/
class CityFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Province>
*/
class ProvinceFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@@ -2,43 +2,32 @@
namespace Database\Factories;
use App\Models\Province;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
* @extends Factory<User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'full_name' => $this->faker->name(),
'username' => $this->faker->userName(),
'position' => $this->faker->randomElement(['boss', 'operator']),
'gender' => $this->faker->randomElement(['female', 'male']),
'national_id' => $this->faker->unique()->numerify('##########'),
'phone_number' => '09' . $this->faker->unique()->randomNumber(9, true),
'province_id' => Province::factory(),
'province_fa' => function (array $attributes) {
return Province::query()->find($attributes['province_id'])->name;
},
'password' => Hash::make('password'),
'email' => $this->faker->email,
'telephone_id' => $this->faker->unique()->numerify('tel-####')
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('provinces', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->double('lat');
$table->double('lon');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('provinces');
}
};

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('cities', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->foreignId('province_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cities');
}
};

View File

@@ -13,20 +13,23 @@ return new class extends Migration
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('full_name');
$table->string('username')->unique();
$table->string('phone_number')->unique();
$table->string('national_id')->unique();
$table->string('position');
$table->string('avatar')->nullable();
$table->enum('gender', [1 => 'female', 2 => 'male'])->nullable();
$table->string('password');
$table->rememberToken();
$table->foreignId('province_id')->constrained('provinces');
$table->string('province_fa');
$table->string('email')->unique()->nullable();
$table->dateTime('last_login')->nullable();
$table->string('telephone_id')->unique();
$table->rememberToken()->nullable();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
@@ -43,7 +46,6 @@ return new class extends Migration
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};

View File

@@ -0,0 +1,19 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class CitySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$sqlFile = file_get_contents(storage_path('/sql-files/cities.sql'));
DB::unprepared($sqlFile);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ProvinceSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$sqlFile = file_get_contents(storage_path('/sql-files/provinces.sql'));
DB::unprepared($sqlFile);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$admin = User::query()->create([
'full_name' => 'Witel Company',
'username' => 'witel',
'phone_number' => '09000000000',
'national_id' => '0150257083',
'password' => Hash::make('Witel@fani0'),
'email' => 'witel@gmail.com',
'position' => 'Software Engineer',
'province_id' => 9,
'province_fa' => "تهران",
'telephone_id' => 0,
]);
// $admin->givePermissionTo(\App\Models\Permission::all());
}
}