Compare commits
5 Commits
c72ba4d7e3
...
610eebf66a
Author | SHA1 | Date | |
---|---|---|---|
|
610eebf66a | ||
|
46d1d616f8 | ||
|
15196c79de | ||
|
fa74b70b98 | ||
|
231a0be5a6 |
13
app/Http/Controllers/Dashboard/DashboardIndexController.php
Normal file
13
app/Http/Controllers/Dashboard/DashboardIndexController.php
Normal 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');
|
||||
}
|
||||
}
|
13
app/Http/Controllers/Dashboard/DashboardUsersController.php
Normal file
13
app/Http/Controllers/Dashboard/DashboardUsersController.php
Normal 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
30
app/Models/Fault.php
Normal 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',
|
||||
];
|
||||
}
|
@ -6,7 +6,6 @@
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
|
@ -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');
|
||||
}
|
||||
};
|
@ -3,11 +3,10 @@
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Fault;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
@ -16,27 +15,75 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
// Create roles if they don't already exist
|
||||
$roles = ['admin', 'privileged'];
|
||||
|
||||
// Create roles
|
||||
$adminRole = Role::create(['name' => 'admin']);
|
||||
$privilegedRole = Role::create(['name' => 'privileged']);
|
||||
foreach ($roles as $roleName) {
|
||||
// Check if the role already exists
|
||||
if (!Role::where('name', $roleName)->exists()) {
|
||||
Role::create(['name' => $roleName]);
|
||||
}
|
||||
}
|
||||
|
||||
// Create permissions
|
||||
$editPermission = Permission::create(['name' => 'edit articles']);
|
||||
$deletePermission = Permission::create(['name' => 'delete articles']);
|
||||
|
||||
// Assign permissions to roles
|
||||
$adminRole->givePermissionTo([$editPermission, $deletePermission]);
|
||||
$privilegedRole->givePermissionTo($editPermission);
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'password' => '12341234'
|
||||
// Check if the superuser already exists
|
||||
$user = User::firstOrCreate([
|
||||
'email' => 'superuser@admin.com',
|
||||
'name' => 'superuser',
|
||||
'password' => bcrypt('12341234'),
|
||||
]);
|
||||
|
||||
$user = User::find(1); // get a user
|
||||
// Assign the role to the superuser
|
||||
$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(),
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
46
resources/views/dashboard/faults.blade.php
Normal file
46
resources/views/dashboard/faults.blade.php
Normal 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>
|
@ -14,4 +14,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</x-app-layout>
|
45
resources/views/dashboard/users.blade.php
Normal file
45
resources/views/dashboard/users.blade.php
Normal 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>
|
@ -16,6 +16,19 @@
|
||||
{{ __('Dashboard') }}
|
||||
</x-nav-link>
|
||||
</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>
|
||||
|
||||
<!-- Settings Dropdown -->
|
||||
|
@ -3,14 +3,30 @@
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Fault;
|
||||
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('home');
|
||||
});
|
||||
|
||||
Route::get('/dashboard', function () {
|
||||
return view('dashboard');
|
||||
$users = \App\Models\User::all();
|
||||
return view('dashboard.index', compact('users'));
|
||||
})->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::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
||||
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
||||
|
Loading…
Reference in New Issue
Block a user