From dc876aa00aa1be86826dd87a8b24e7583331bcdf Mon Sep 17 00:00:00 2001 From: Adrian Tejeda Date: Tue, 1 Sep 2026 20:42:00 -0300 Subject: [PATCH] Agrego login y ajustes de mensajes --- app/Http/Controllers/Auth/LoginController.php | 32 +++- app/Http/Controllers/PersonaController.php | 12 ++ app/Models/Persona.php | 6 + app/Traits/Herramientas.php | 15 ++ resources/views/welcome.blade.php | 149 +++++------------- routes/web.php | 13 -- 6 files changed, 100 insertions(+), 127 deletions(-) create mode 100644 app/Traits/Herramientas.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index ab8c37c..5a2ccbe 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class LoginController extends Controller { @@ -37,4 +39,32 @@ class LoginController extends Controller $this->middleware('guest')->except('logout'); $this->middleware('auth')->only('logout'); } -} + + public function login(Request $request) + { + $credentials = $request->validate([ + 'email' => 'required|email', + 'password' => 'required', + ]); + + if (Auth::attempt($credentials)) { + $request->session()->regenerate(); + + return redirect()->intended('/'); + } + + return back()->withErrors([ + 'email' => 'Las credenciales no coinciden con nuestros registros.', + ]); + } + + public function logout(Request $request) + { + Auth::logout(); + + $request->session()->invalidate(); + $request->session()->regenerateToken(); + + return redirect('/login'); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/PersonaController.php b/app/Http/Controllers/PersonaController.php index a954306..b776c77 100644 --- a/app/Http/Controllers/PersonaController.php +++ b/app/Http/Controllers/PersonaController.php @@ -32,9 +32,21 @@ class PersonaController extends Controller return view('personas.index', ["personas"=>$personas]); } + + public function show($id){ $persona = Persona::findOrfail($id); + $persona->formatear_texto(); return view('personas.show', ["per"=>$persona]); + + + + + + + + + } public function destroy(Request $request, $id){ diff --git a/app/Models/Persona.php b/app/Models/Persona.php index 0e8123f..0808991 100644 --- a/app/Models/Persona.php +++ b/app/Models/Persona.php @@ -5,11 +5,17 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use App\Traits\Herramientas; +{ + +} + class Persona extends Model { use HasFactory; use SoftDeletes; + use Herramientas; protected $table = 'personas'; diff --git a/app/Traits/Herramientas.php b/app/Traits/Herramientas.php new file mode 100644 index 0000000..7df7ce2 --- /dev/null +++ b/app/Traits/Herramientas.php @@ -0,0 +1,15 @@ +nombre = ucwords(strtolower($this->nombre)); + $this->apellido = ucwords(strtolower($this->apellido)); + $this->update(); + } + +} + diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 3353350..4d4dd2b 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -6,128 +6,51 @@ Laravel - - - - - - + - -
- @if (Route::has('login')) -
- @auth - Home - @else - Log in - @if (Route::has('register')) - Register - @endif - @endauth -
- @endif + +
-
-
- - - +

Bienvenidos al sistema

+
+ + @auth +
+

Usuario autenticado

+ +

+ El usuario es: + {{ Auth::user()->name }} +

+ +

+ El mail es: + {{ Auth::user()->email }} +

-
-
- -
-
- - - -
+
+ Ir a Personas + + @endauth -

Documentation

+ @guest +
+

Usuario no autenticado

-

- Laravel has wonderful documentation covering every aspect of the framework. Whether you are a newcomer or have prior experience with Laravel, we recommend reading our documentation from beginning to end. -

-
- - - - - - - -
-
- - - -
- -

Laracasts

- -

- Laracasts offers thousands of video tutorials on Laravel, PHP, and JavaScript development. Check them out, see for yourself, and massively level up your development skills in the process. -

-
- - - - -
- - -
-
- - - -
- -

Laravel News

- -

- Laravel News is a community driven portal and newsletter aggregating all of the latest and most important news in the Laravel ecosystem, including new package releases and tutorials. -

-
- - - - -
- -
-
-
- - - -
- -

Vibrant Ecosystem

- -

- Laravel's robust library of first-party tools and libraries, such as Forge, Vapor, Nova, and Envoyer help you take your projects to the next level. Pair them with powerful open source libraries like Cashier, Dusk, Echo, Horizon, Sanctum, Telescope, and more. -

-
-
-
+

Debe iniciar sesión

-
-
-   -
+ + Iniciar sesión + + @endguest -
- Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }}) -
-
-
- + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index f9a6b73..5a1dc54 100644 --- a/routes/web.php +++ b/routes/web.php @@ -8,19 +8,6 @@ Route::get('/', function () { return view('welcome'); }); -/*Route::get('personas', [PersonaController::class, 'index'])->name('personas.index'); listar -Route::post('personas', [PersonaController::class, 'store'])->name('personas.store'); guardar -Route::get('personas/create', [PersonaController::class, 'create'])->name('personas.create'); crear -Route::get('personas/{persona}', [PersonaController::class, 'show'])->name('personas.show'); ver -Route::delete('personas/{persona}', [PersonaController::class, 'destroy'])->name('personas.destroy'); eliminar -Route::get('personas/{persona}/edit', [PersonaController::class, 'edit'])->name('personas.edit'); editar -Route::put('personas/{persona}', [PersonaController::class, 'update'])->name('personas.update'); actualizar*/ - -/* -Adrian: Route::Resourse y Restaurar - -Fabri: REST -*/ Route::resource('personas', PersonaController::class); Route::put('personas/restaurar/{persona}', [PersonaController::class, 'restaurar'])->name('personas.restaurar');