Add Laravel Sanctum for API authentication and update routes
- Included `laravel/sanctum` in `composer.json` for lightweight API authentication. - Updated `User` model to use `HasApiTokens` trait for token management. - Configured API routing in `bootstrap/app.php`. - Modified `DatabaseSeeder` to include `ShieldSeeder` and adjusted `FillJsonData` seeder method. - Changed JSON data path in `ProvincesMigrator` for testing purposes. - Updated web routes to utilize `MigrationController` for better organization.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?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('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->text('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
||||
@@ -13,9 +13,7 @@ class DatabaseSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
FillJsonData::class,
|
||||
// UsersTableSeeder::class,
|
||||
// ShieldSeeder::class,
|
||||
ShieldSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ class FillJsonData extends Seeder
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void {}
|
||||
public function run(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function seedUsers(): void
|
||||
{
|
||||
|
||||
26
database/seeders/Migrators/PersonalAccessTokensMigrator.php
Normal file
26
database/seeders/Migrators/PersonalAccessTokensMigrator.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders\Migrators;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class PersonalAccessTokensMigrator
|
||||
{
|
||||
public function migrate(): void
|
||||
{
|
||||
DB::table('personal_access_tokens')->truncate();
|
||||
|
||||
$path = database_path('data/tested/personal_access_tokens.json');
|
||||
|
||||
$rawData = File::json($path);
|
||||
|
||||
foreach ($rawData as $data) {
|
||||
DB::table('personal_access_tokens')
|
||||
->insert($data);
|
||||
}
|
||||
|
||||
DB::statement("SELECT setval('personal_access_tokens_id_seq', (SELECT MAX(id) from personal_access_tokens));");
|
||||
DB::statement("SELECT nextval('personal_access_tokens_id_seq');");
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class ProvincesMigrator
|
||||
{
|
||||
DB::table('provinces')->truncate();
|
||||
|
||||
$path = database_path('data/nurmuhammetsdb/provinces.json');
|
||||
$path = database_path('data/tested/provinces.json');
|
||||
|
||||
$rawData = File::json($path);
|
||||
|
||||
|
||||
26
database/seeders/Migrators/VerificationsMigrator.php
Normal file
26
database/seeders/Migrators/VerificationsMigrator.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders\Migrators;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class VerificationsMigrator
|
||||
{
|
||||
public function migrate(): void
|
||||
{
|
||||
DB::table('verifications')->truncate();
|
||||
|
||||
$path = database_path('data/tested/verifications.json');
|
||||
|
||||
$rawData = File::json($path);
|
||||
|
||||
foreach ($rawData as $data) {
|
||||
DB::table('verifications')
|
||||
->insert($data);
|
||||
}
|
||||
|
||||
DB::statement("SELECT setval('verifications_id_seq', (SELECT MAX(id) from verifications));");
|
||||
DB::statement("SELECT nextval('verifications_id_seq');");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user