añadir nuevas funcionalidades
This commit is contained in:
51
database/migrations/2025_04_29_115501_update_users_table.php
Normal file
51
database/migrations/2025_04_29_115501_update_users_table.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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::table('users', function (Blueprint $table) {
|
||||
$table->string('title')->nullable()->after('id');
|
||||
$table->string('first_name')->after('title');
|
||||
$table->string('last_name')->after('first_name');
|
||||
$table->string('username')->unique()->after('last_name');
|
||||
$table->date('access_start')->nullable()->after('password');
|
||||
$table->date('access_end')->nullable()->after('access_start');
|
||||
$table->string('phone')->nullable()->after('email');
|
||||
$table->text('address')->nullable()->after('phone');
|
||||
$table->boolean('is_active')->default(true)->after('address');
|
||||
$table->string('profile_photo_path')->nullable();
|
||||
|
||||
// Eliminar campos no necesarios
|
||||
$table->dropColumn('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('title');
|
||||
$table->dropColumn('first_name');
|
||||
$table->dropColumn('last_name');
|
||||
$table->dropColumn('username');
|
||||
$table->dropColumn('access_start');
|
||||
$table->dropColumn('access_end');
|
||||
$table->dropColumn('phone');
|
||||
$table->dropColumn('address');
|
||||
$table->dropColumn('is_active');
|
||||
$table->dropColumn('profile_photo_path ');
|
||||
|
||||
$table->string('name')->after('id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -3,9 +3,8 @@
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
@@ -16,10 +15,14 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'admin',
|
||||
User::create([
|
||||
'first_name' => 'Administrador',
|
||||
'last_name' => '',
|
||||
'username' => 'admin',
|
||||
'email' => 'admin@example.com',
|
||||
'password' => '12345678',
|
||||
'password' => Hash::make('12345678'),
|
||||
'is_active' => true,
|
||||
'access_start' => now(),
|
||||
]);
|
||||
|
||||
$this->call([
|
||||
|
||||
@@ -56,15 +56,6 @@ class RolePermissionSeeder extends Seeder
|
||||
$adminRole->syncPermissions($allPermissions);
|
||||
$adminRole->syncPermissions($permissions);
|
||||
|
||||
// Crear usuario admin si no existe
|
||||
/*User::updateOrCreate(
|
||||
['email' => env('ADMIN_EMAIL', 'admin@example.com')],
|
||||
[
|
||||
'name' => 'Administrador',
|
||||
'password' => bcrypt(env('ADMIN_PASSWORD', 'password')),
|
||||
'email_verified_at' => now()
|
||||
]
|
||||
)->assignRole($adminRole);*/
|
||||
$adminEmail = env('ADMIN_EMAIL', 'admin@example.com');
|
||||
$user = User::where('email', $adminEmail)->first();
|
||||
if ($user) {
|
||||
@@ -75,9 +66,11 @@ class RolePermissionSeeder extends Seeder
|
||||
} else {
|
||||
// Crear solo si no existe
|
||||
User::create([
|
||||
'name' => 'admin',
|
||||
'email' => $adminEmail,
|
||||
'password' => bcrypt(env('ADMIN_PASSWORD', '12345678')),
|
||||
'first_name' => 'Administrador',
|
||||
'username' => 'admin',
|
||||
'email' => 'admin@example.com',
|
||||
'password' => '12345678',
|
||||
'is_active' => true,
|
||||
'email_verified_at' => now()
|
||||
])->assignRole($adminRole);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user