diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 961ea36..9cffb73 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -4,7 +4,7 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use App\Models\User; -use Illuminate\Foundation\Auth\RegistersUsers; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; @@ -21,8 +21,6 @@ class RegisterController extends Controller | */ - use RegistersUsers; - /** * Where to redirect users after registration. * @@ -40,6 +38,28 @@ class RegisterController extends Controller $this->middleware('guest'); } + // Método para mostrar el formulario de registro + public function showRegistrationForm() + { + return view('auth.register'); + } + + // Método para manejar el registro + public function register(Request $request) + { + // Validar los datos del usuario + $this->validator($request->all())->validate(); + + // Crear el usuario + $user = $this->create($request->all()); + + // Autenticar al usuario + auth()->login($user); + + // Redirigir a la página principal + return redirect()->route('home')->with('success', 'Registro exitoso. Bienvenido!'); + } + /** * Get a validator for an incoming registration request. * diff --git a/app/Http/Controllers/MarcaController.php b/app/Http/Controllers/MarcaController.php new file mode 100644 index 0000000..ba4913e --- /dev/null +++ b/app/Http/Controllers/MarcaController.php @@ -0,0 +1,97 @@ +busqueda; + + if($busqueda) { + $marcas = Marca::where('nombre', 'LIKE', "%{$busqueda}%")->get(); + + if($marcas->count() == 0) { + return redirect()->route('marca.index') + ->with('error', 'No existe ninguna marca con el nombre "' . $busqueda . '". Por favor, inténtalo de nuevo.'); + } + + // Si solo hay una marca, mostrar sus detalles + if($marcas->count() == 1) { + $marca = $marcas->first(); + return redirect()->route('marca.edit', $marca->id); + } + + // Si hay múltiples coincidencias, mostrar la lista filtrada + return view('marca', ["marcas" => $marcas]); + } + + // Si no hay búsqueda, mostrar todas las marcas + $marcas = Marca::all(); + return view('marcas', ["marcas" => $marcas]); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + $marcas = Marca::all(); + return view('marcasCrearEditar',['marcas'=>$marcas]); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + $marca = new Marca($request->all()); + $marca->save(); + return redirect()->route('marca.index')->with('success', 'Marca creada exitosamente.'); + } + + /** + * Display the specified resource. + */ + public function show(Marca $marca) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit($id) + { + $marca = Marca::find($id); + return view('marcasCrearEditar',['marca'=>$marca]); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, $id) + { + $marca = Marca::find($id); + $marca->fill($request->all()); + $marca->save(); + return redirect()->route('marca.index'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy($id ) + { + $marca = Marca::find($id); + $marca->delete(); + return redirect()->route('marca.index')->with('success', 'Marca eliminada exitosamente.'); + + } +} diff --git a/app/Http/Controllers/usuariosController.php b/app/Http/Controllers/usuariosController.php index 7ef48c1..d6a7a48 100644 --- a/app/Http/Controllers/usuariosController.php +++ b/app/Http/Controllers/usuariosController.php @@ -10,11 +10,11 @@ class usuariosController extends Controller /** * Display a listing of the resource. */ - public function index() + public function index(Request $request) { - $user=User::all(); + $usuarios = User::all(); - return view('usuarios',['user'=>$user]); + return view('usuarios', compact('usuarios')); } /** @@ -22,8 +22,7 @@ class usuariosController extends Controller */ public function create() { - return view('usuariosCrearEditar'); - + return view('usuarios.create'); } /** @@ -31,10 +30,19 @@ class usuariosController extends Controller */ public function store(Request $request) { + $request->validate([ + 'name' => 'required|string|max:255', + 'email' => 'required|string|email|max:255|unique:users', + 'password' => 'required|string|min:8|confirmed', + ]); + + User::create([ + 'name' => $request->name, + 'email' => $request->email, + 'password' => bcrypt($request->password), + ]); - $user = new User($request->all()); - $user->save(); - return redirect()->route('usuarios'); + return redirect()->route('usuarios')->with('success', 'Usuario creado exitosamente.'); } /** @@ -48,24 +56,27 @@ class usuariosController extends Controller /** * Show the form for editing the specified resource. */ - public function edit(string $id) + public function edit($id) { - // + } /** * Update the specified resource in storage. */ - public function update(Request $request, string $id) + public function update(Request $request, $id) { - // + } /** * Remove the specified resource from storage. */ - public function destroy(string $id) + public function destroy($id) { - // + $usuario = User::findOrFail($id); + $usuario->delete(); + + return redirect()->route('usuarios')->with('success', 'Usuario eliminado exitosamente.'); } } diff --git a/app/Models/Marca.php b/app/Models/Marca.php new file mode 100644 index 0000000..91be636 --- /dev/null +++ b/app/Models/Marca.php @@ -0,0 +1,15 @@ + + */ +class MarcaFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2025_02_28_192615_create_marcas_table.php b/database/migrations/2025_02_28_192615_create_marcas_table.php new file mode 100644 index 0000000..cb30b5f --- /dev/null +++ b/database/migrations/2025_02_28_192615_create_marcas_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('nombre'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('marcas'); + } +}; diff --git a/database/seeders/MarcaSeeder.php b/database/seeders/MarcaSeeder.php new file mode 100644 index 0000000..bd53b8c --- /dev/null +++ b/database/seeders/MarcaSeeder.php @@ -0,0 +1,17 @@ + diff --git a/resources/views/layouts/dashboard.blade.php b/resources/views/layouts/dashboard.blade.php index 5b3d6b6..2f09da5 100644 --- a/resources/views/layouts/dashboard.blade.php +++ b/resources/views/layouts/dashboard.blade.php @@ -10,6 +10,8 @@ + +
@@ -66,6 +68,14 @@ x-transition:leave-end="opacity-0 transform -translate-y-2" class="pl-4 mt-2 space-y-1 text-sm"> + +
  • + + + Marca + +
  • +
  • diff --git a/resources/views/marcas.blade.php b/resources/views/marcas.blade.php new file mode 100644 index 0000000..f1c6d52 --- /dev/null +++ b/resources/views/marcas.blade.php @@ -0,0 +1,134 @@ +@extends('layouts.dashboard') + +@section('content') +
    + + @if(session('success')) + + @endif + + @if(session('error')) + + @endif + +
    + + + +
    +
    +
    + +
    + +
    +
    + + @if(request('busqueda')) + + Limpiar + + @endif +
    +
    + +
    + + + + + + + + + + + @foreach($marcas as $marca) + + + + + + @endforeach + +
    IDMarcaAcciones
    {{ $marca->id }} + + {{ $marca->nombre }} + +
    + + + +
    + @csrf + @method('DELETE') + +
    +
    +
    +
    +
    +
    + + +@endsection diff --git a/resources/views/marcasCrearEditar.blade.php b/resources/views/marcasCrearEditar.blade.php new file mode 100644 index 0000000..c3f0aa5 --- /dev/null +++ b/resources/views/marcasCrearEditar.blade.php @@ -0,0 +1,132 @@ +@extends('layouts.dashboard') + +@section('content') +
    +
    +
    +
    + +
    +

    + {{ isset($marca) ? 'Editar Marca' : 'Nueva Marca' }} +

    +
    + +
    +
    + + + @if($errors->any()) +
    +
    + +
    +
      + @foreach($errors->all() as $error) +
    • {{ $error }}
    • + @endforeach +
    +
    +
    +
    + @endif + + +
    + @csrf + @if(isset($marca)) + @method('PUT') + @endif + +
    + +
    + +
    +
    + +
    + +
    + @error('nombre') +

    {{ $message }}

    + @enderror +
    + + +
    + + Cancelar + + +
    +
    +
    +
    +
    +
    +
    + + +@endsection diff --git a/resources/views/usuarios.blade.php b/resources/views/usuarios.blade.php new file mode 100644 index 0000000..2929466 --- /dev/null +++ b/resources/views/usuarios.blade.php @@ -0,0 +1,108 @@ +@extends('layouts.dashboard') + +@section('content') +
    + + @if(session('success')) + + @endif + + @if(session('error')) + + @endif + +
    +
    +

    Gestión de Usuarios

    +
    + + +
    +
    +
    + +
    + +
    +
    + + @if(request('busqueda')) + + Limpiar + + @endif +
    +
    + +
    + + + + + + + + + + + @if($usuarios->isEmpty()) + + + + @else + @foreach($usuarios as $usuario) + + + + + + + @endforeach + @endif + +
    IDNombreEmailAcciones
    No hay usuarios registrados.
    {{ $usuario->id }}{{ $usuario->name }}{{ $usuario->email }} +
    +
    +
    + @csrf + @method('DELETE') + +
    +
    +
    +
    +
    +
    + + +@endsection diff --git a/routes/web.php b/routes/web.php index 30c7c62..96f55b6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,7 +3,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\usuariosController; use App\Http\Controllers\HomeController; - +use App\Http\Controllers\MarcaController; /* |-------------------------------------------------------------------------- | Web Routes @@ -19,7 +19,10 @@ Route::get('/', function () { return redirect()->route('dashboard'); }); -Auth::routes(['register'=>true,'reset'=>true]); +Auth::routes(['register'=>true,'reset'=>false]); + +Route::resource('marca', MarcaController::class); + // Rutas protegidas que requieren autenticación Route::middleware(['auth'])->group(function () { @@ -27,4 +30,8 @@ Route::middleware(['auth'])->group(function () { Route::get('/usuarios', [usuariosController::class,'index'])->name('usuarios'); Route::get('/usuarios/nuevo', [usuariosController::class,'create'])->name('usuarios.create'); Route::post('/usuarios/store', [usuariosController::class,'store'])->name('usuarios.store'); + Route::get('/usuarios/{id}/edit', [usuariosController::class, 'edit'])->name('usuarios.edit'); + Route::put('/usuarios/{id}', [usuariosController::class, 'update'])->name('usuarios.update'); + Route::delete('/usuarios/{id}', [usuariosController::class, 'destroy'])->name('usuarios.destroy'); + Route::get('/home', [HomeController::class, 'index'])->name('home'); });