Compare commits

..

5 Commits

Author SHA1 Message Date
albert
610eebf66a add faults (routes, model, navigation, seeder and migration)
All checks were successful
Build, push and deploy / builds (push) Successful in 5s
2024-11-08 16:39:01 +01:00
albert
46d1d616f8 prepare controllers 2024-11-08 02:29:09 +01:00
albert
15196c79de database seeder refactor 2024-11-08 02:28:55 +01:00
albert
fa74b70b98 dashboard.view 2024-11-08 02:28:37 +01:00
albert
231a0be5a6 changes default superuser 2024-11-08 00:56:51 +01:00
11 changed files with 280 additions and 23 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers\Dashboard;
use App\Http\Controllers\Controller;
class DashboardIndexController extends Controller
{
public function create(): View
{
return view('dashboard.index');
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers\Dashboard;
use App\Http\Controllers\Controller;
class DashboardIndexController extends Controller
{
public function create(): View
{
return view('dashboard.users');
}
}

30
app/Models/Fault.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
class Fault extends Model
{
use HasFactory, Notifiable;
use HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'contact_name',
'contact_phone',
'description',
'address',
'status',
'google_maps_link',
'city',
];
}

View File

@ -6,7 +6,6 @@
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles; use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable class User extends Authenticatable

View File

@ -0,0 +1,34 @@
<?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('faults', function (Blueprint $table) {
$table->id();
$table->string('contact_name'); // This column must exist
$table->string('contact_phone');
$table->text('description');
$table->string('address');
$table->string('status');
$table->string('google_maps_link');
$table->string('city');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('faults');
}
};

View File

@ -3,11 +3,10 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\User; use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; use App\Models\Fault;
use Illuminate\Database\Seeder;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role; use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
@ -16,27 +15,75 @@ class DatabaseSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
// User::factory(10)->create(); // Create roles if they don't already exist
$roles = ['admin', 'privileged'];
// Create roles foreach ($roles as $roleName) {
$adminRole = Role::create(['name' => 'admin']); // Check if the role already exists
$privilegedRole = Role::create(['name' => 'privileged']); if (!Role::where('name', $roleName)->exists()) {
Role::create(['name' => $roleName]);
}
}
// Create permissions // Check if the superuser already exists
$editPermission = Permission::create(['name' => 'edit articles']); $user = User::firstOrCreate([
$deletePermission = Permission::create(['name' => 'delete articles']); 'email' => 'superuser@admin.com',
'name' => 'superuser',
// Assign permissions to roles 'password' => bcrypt('12341234'),
$adminRole->givePermissionTo([$editPermission, $deletePermission]);
$privilegedRole->givePermissionTo($editPermission);
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
'password' => '12341234'
]); ]);
$user = User::find(1); // get a user // Assign the role to the superuser
$user->assignRole('admin'); $user->assignRole('admin');
// Create other users as before
$users = [
['name' => 'John Doe', 'email' => 'john@doe.com', 'role' => 'privileged'],
['name' => 'Chuck Norris', 'email' => 'chuck@norris.com'],
['name' => 'Marios Bros', 'email' => 'mario@bros.com'],
['name' => 'Ada Lovelace', 'email' => 'ada@lovelace.com'],
['name' => 'Hulk Hogan', 'email' => 'hulk@hogart.com'],
];
foreach ($users as $userData) {
$user = User::firstOrCreate([
'email' => $userData['email'],
'name' => $userData['name'],
'password' => bcrypt('12341234'),
]);
if (array_key_exists('role', $userData) && $userData['role']) {
$user->assignRole($userData['role']);
} }
} }
Fault::firstOrCreate([
'contact_name' => 'Anthony',
'contact_phone' => '666767222',
'description' => 'No tenemos luz en el garaje',
'address' => 'Carrer del mig, 4',
'status' => 'En espera',
'google_maps_link' => 'https://maps.google.com/long/url/link',
'city' => 'Algemesi',
'created_at' => now(),
'updated_at' => now(),
]);
Fault::firstOrCreate([
'contact_name' => 'Amparo',
'contact_phone' => '74645657',
'description' => 'Se ha roto el reloj',
'address' => 'Plaza Mayor 1',
'status' => 'Realizado',
'google_maps_link' => 'https://maps.google.com/long/url/link',
'city' => 'Cataroja',
'created_at' => now(),
'updated_at' => now(),
]);
}
}

View File

@ -0,0 +1,46 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Averías') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="overflow-x-auto py-4">
<table class="min-w-full table-auto border-collapse">
<thead>
<tr>
<!-- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th> -->
<!-- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th> -->
<!-- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Direcció</th> -->
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ciutat</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Telefon</th>
<!-- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Google Maps</th> -->
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach ($faults as $fault)
<tr>
<!-- <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ $fault->id }}</td> -->
<!-- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $fault->contact_name }}</td> -->
<!-- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->address }}</td> -->
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->status }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->city }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->contact_phone }}</td>
<!-- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->google_maps_link }}</td> -->
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button class="text-indigo-600 hover:text-indigo-900">Edit</button>
<button class="text-red-600 hover:text-red-900 ml-4">Delete</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</x-app-layout>

View File

@ -14,4 +14,5 @@
</div> </div>
</div> </div>
</div> </div>
</x-app-layout> </x-app-layout>

View File

@ -0,0 +1,45 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Usuarios') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="overflow-x-auto py-4">
<table class="min-w-full table-auto border-collapse">
<thead>
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Created At</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Updated At</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Roles</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach ($users as $user)
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">1</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $user->name }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $user->email }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $user->created_at }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $user->updated_at }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ implode(', ', $user->getRoleNames()->toArray()) }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button class="text-indigo-600 hover:text-indigo-900">Edit</button>
<button class="text-red-600 hover:text-red-900 ml-4">Delete</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</x-app-layout>

View File

@ -16,6 +16,19 @@
{{ __('Dashboard') }} {{ __('Dashboard') }}
</x-nav-link> </x-nav-link>
</div> </div>
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
<x-nav-link :href="route('dashboard.users')" :active="request()->routeIs('dashboard.users')">
{{ __('Usuarios') }}
</x-nav-link>
</div>
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
<x-nav-link :href="route('dashboard.faults')" :active="request()->routeIs('dashboard.faults')">
{{ __('Averías') }}
</x-nav-link>
</div>
</div> </div>
<!-- Settings Dropdown --> <!-- Settings Dropdown -->

View File

@ -3,14 +3,30 @@
use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use App\Models\User;
use App\Models\Fault;
Route::get('/', function () { Route::get('/', function () {
return view('home'); return view('home');
}); });
Route::get('/dashboard', function () { Route::get('/dashboard', function () {
return view('dashboard'); $users = \App\Models\User::all();
return view('dashboard.index', compact('users'));
})->middleware(['auth', 'verified'])->name('dashboard'); })->middleware(['auth', 'verified'])->name('dashboard');
// Subroute for users under /dashboard/users
Route::get('/dashboard/users', function () {
$users = \App\Models\User::all();
return view('dashboard.users', compact('users'));
})->name('dashboard.users');
Route::get('/dashboard/faults', function () {
$faults = \App\Models\Fault::all();
return view('dashboard.faults', compact('faults'));
})->name('dashboard.faults');
Route::middleware('auth')->group(function () { Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');