27 changed files with 774 additions and 5 deletions
			
			
		| @ -0,0 +1,69 @@ | |||
| <?php | |||
| 
 | |||
| namespace App\Http\Controllers; | |||
| 
 | |||
| use App\Models\Auto; | |||
| use Illuminate\Http\Request; | |||
| 
 | |||
| class AutoController extends Controller | |||
| { | |||
|     /** | |||
|      * Display a listing of the resource. | |||
|      */ | |||
|     public function index() | |||
|     { | |||
|         $autos = Auto::all(); | |||
|         return view('autos', ['autos' => $autos]); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Show the form for creating a new resource. | |||
|      */ | |||
|     public function create() | |||
|     { | |||
|         return view('autosCrearEditar', ['auto' => null]); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Store a newly created resource in storage. | |||
|      */ | |||
|     public function store(Request $request) | |||
|     { | |||
|         $auto = Auto::create($request->all()); | |||
|         return redirect()->route('autos.index'); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Display the specified resource. | |||
|      */ | |||
|     public function show(Auto $auto) | |||
|     { | |||
|         return view('autosCrearEditar', ['auto' => $auto]); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Show the form for editing the specified resource. | |||
|      */ | |||
|     public function edit(Auto $auto) | |||
|     { | |||
|         return view('autosCrearEditar', ['auto' => $auto]); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Update the specified resource in storage. | |||
|      */ | |||
|     public function update(Request $request, Auto $auto) | |||
|     { | |||
|         $auto->update($request->all()); | |||
|         return redirect()->route('autos.index'); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Remove the specified resource from storage. | |||
|      */ | |||
|     public function destroy(Auto $auto) | |||
|     { | |||
|         $auto->delete(); | |||
|         return redirect()->route('autos.index'); | |||
|     } | |||
| } | |||
| @ -0,0 +1,82 @@ | |||
| <?php | |||
| 
 | |||
| namespace App\Http\Controllers; | |||
| 
 | |||
| use App\Models\Trabajador; | |||
| use Illuminate\Http\Request; | |||
| use App\Models\Puesto; | |||
| 
 | |||
| class TrabajadorController extends Controller | |||
| { | |||
|     /** | |||
|      * Display a listing of the resource. | |||
|      */ | |||
|     public function index() | |||
|     { | |||
|         $trabajadores = Trabajador::all(); | |||
|         return view('trabajadores', ['trabajadores' => $trabajadores]); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Show the form for creating a new resource. | |||
|      */ | |||
|     public function create() | |||
|     { | |||
|         $puestos = Puesto::all(); | |||
|         return view('trabajadoresCrearEditar', ['trabajador' => null, 'puestos' => $puestos]); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Store a newly created resource in storage. | |||
|      */ | |||
|     public function store(Request $request) | |||
|     { | |||
| 
 | |||
|         $trabajador2 = new Trabajador($request->all()); | |||
|         $trabajador2->save(); | |||
|         return redirect()->route('trabajadores.index')->with('succes',value: 'El auto se agregó'); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Display the specified resource. | |||
|      */ | |||
|     public function show(Trabajador $trabajador) | |||
|     { | |||
|         // | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Show the form for editing the specified resource. | |||
|      */ | |||
|     public function edit($id) | |||
|     { | |||
|         $puestos = Puesto::all(); | |||
|         $trabajador = Trabajador::find($id); | |||
|         return view('trabajadoresCrearEditar', ['trabajador' => $trabajador, 'puestos' => $puestos])->with(key: 'warning', value:'Actualizado correctamente'); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Update the specified resource in storage. | |||
|      */ | |||
|     public function update(Request $request, $id) | |||
|     { | |||
|         $trabajador = Trabajador::find($id); //Busca el trabajador por el id | |||
|         $trabajador->update($request->all()); //Actualiza los datos del trabajador | |||
|         return redirect()->route('trabajadores.index')->with(key: 'warning', value:'Actualizado correctamente'); //Redirecciona a la página de index | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Remove the specified resource from storage. | |||
|      */ | |||
|     public function destroy($id) | |||
|     { | |||
|         $trabajador = Trabajador::find($id); //Busca el trabajador por el id | |||
|         if($trabajador->puesto_id()!=1){ | |||
|         $trabajador->delete(); //Elimina el trabajador: | |||
|         return redirect()->route('trabajadores.index')->with(key: 'succes', value:'Eliminado correctamente'); //Redirecciona a la página de index | |||
|         }else{ | |||
|             return redirect()->route('trabajadores.index')->with(key: 'error', value:'No se puede eliminar el trabajador porque no tiene un puesto asignado'); //Redirecciona a la página de index | |||
|         } | |||
|     } | |||
| 
 | |||
| } | |||
| @ -0,0 +1,14 @@ | |||
| <?php | |||
| 
 | |||
| namespace App\Models; | |||
| 
 | |||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | |||
| use Illuminate\Database\Eloquent\Model; | |||
| 
 | |||
| class Auto extends Model | |||
| { | |||
|     use HasFactory; | |||
|     protected $table = 'autos'; | |||
| 
 | |||
|     protected $fillable = ['marca', 'modelo', 'año', 'color', 'precio']; | |||
| } | |||
| @ -0,0 +1,19 @@ | |||
| <?php | |||
| 
 | |||
| namespace App\Models; | |||
| 
 | |||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | |||
| use Illuminate\Database\Eloquent\Model; | |||
| use Illuminate\Database\Eloquent\Relations\HasMany; | |||
| 
 | |||
| class Puesto extends Model | |||
| { | |||
|     use HasFactory; | |||
|     protected $table = 'puestos'; | |||
|     protected $fillable = ['nombre']; | |||
| 
 | |||
|     public function trabajadores(): hasMany | |||
|     { | |||
|         return $this->hasMany(Trabajador::class,'puesto_id','id'); | |||
|     } | |||
| } | |||
| @ -0,0 +1,20 @@ | |||
| <?php | |||
| 
 | |||
| namespace App\Models; | |||
| 
 | |||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | |||
| use Illuminate\Database\Eloquent\Model; | |||
| use Illuminate\Database\Eloquent\Relations\HasOne; | |||
| class Trabajador extends Model | |||
| { | |||
| 
 | |||
|     use HasFactory; | |||
|     protected $table = 'trabajadors'; | |||
| 
 | |||
|     protected $fillable = ['nombre', 'telefono', 'genero', 'sueldo', 'puesto_id', 'numero_seguro', 'correo_electronico']; | |||
| 
 | |||
|     public function Puesto(): hasOne | |||
|     { | |||
|         return $this->hasOne(Puesto::class,'id','puesto_id'); | |||
|     } | |||
| } | |||
| @ -0,0 +1,27 @@ | |||
| <?php | |||
| 
 | |||
| namespace Database\Factories; | |||
| 
 | |||
| use Illuminate\Database\Eloquent\Factories\Factory; | |||
| 
 | |||
| /** | |||
|  * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Auto> | |||
|  */ | |||
| class AutoFactory extends Factory | |||
| { | |||
|     /** | |||
|      * Define the model's default state. | |||
|      * | |||
|      * @return array<string, mixed> | |||
|      */ | |||
|     public function definition(): array | |||
|     { | |||
|         return [ | |||
|             'marca' => $this->faker->randomElement(['Toyota', 'Ford', 'Chevrolet', 'Nissan', 'Honda']), | |||
|             'modelo' => $this->faker->randomElement(['Corolla', 'F150', 'Camry', 'Altima', 'Civic']), | |||
|             'año' => $this->faker->year(), | |||
|             'color' => $this->faker->colorName(), | |||
|             'precio' => $this->faker->randomFloat(2, 10000, 50000), | |||
|         ]; | |||
|     } | |||
| } | |||
| @ -0,0 +1,29 @@ | |||
| <?php | |||
| 
 | |||
| namespace Database\Factories; | |||
| 
 | |||
| use Illuminate\Database\Eloquent\Factories\Factory; | |||
| 
 | |||
| /** | |||
|  * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Trabajador> | |||
|  */ | |||
| class TrabajadorFactory extends Factory | |||
| { | |||
|     /** | |||
|      * Define the model's default state. | |||
|      * | |||
|      * @return array<string, mixed> | |||
|      */ | |||
|     public function definition(): array | |||
|     { | |||
|         return [ | |||
|             'nombre'=> $this->faker->name, | |||
|             'telefono'=> $this->faker->phoneNumber(), | |||
|             'genero'=> $this->faker->randomElement(['Masculino','Femenino']), | |||
|             'sueldo'=> $this->faker->randomFloat(2, 1000, 100000), | |||
|             'puesto'=> $this->faker->jobTitle(), | |||
|             'numero_seguro'=> $this->faker->randomNumber(8), | |||
|             'correo_electronico'=> $this->faker->email(), | |||
|         ]; | |||
|     } | |||
| } | |||
| @ -0,0 +1,38 @@ | |||
| <?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('puestos', function (Blueprint $table) { | |||
|             $table->id(); | |||
|             $table->string('nombre'); | |||
|             $table->timestamps(); | |||
|         }); | |||
| 
 | |||
|         DB::table('puestos')->insert([ | |||
|             'nombre' => 'Administrador', | |||
|         ]); | |||
|         DB::table('puestos')->insert([ | |||
|             'nombre' => 'Mesero', | |||
|         ]); | |||
|         DB::table('puestos')->insert([ | |||
|             'nombre' => 'Cocinero', | |||
|         ]); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Reverse the migrations. | |||
|      */ | |||
|     public function down(): void | |||
|     { | |||
|         Schema::dropIfExists('puestos'); | |||
|     } | |||
| }; | |||
| @ -0,0 +1,32 @@ | |||
| <?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('autos', function (Blueprint $table) { | |||
|             $table->id(); | |||
|             $table->string('marca'); | |||
|             $table->string('modelo'); | |||
|             $table->integer('año'); | |||
|             $table->string('color'); | |||
|             $table->decimal('precio', 8, 2); | |||
|             $table->timestamps(); | |||
|         }); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Reverse the migrations. | |||
|      */ | |||
|     public function down(): void | |||
|     { | |||
|         Schema::dropIfExists('autos'); | |||
|     } | |||
| }; | |||
| @ -0,0 +1,36 @@ | |||
| <?php | |||
| 
 | |||
| use Illuminate\Database\Migrations\Migration; | |||
| use Illuminate\Database\Schema\Blueprint; | |||
| use Illuminate\Support\Facades\Schema; | |||
| use PhpParser\Node\NullableType; | |||
| 
 | |||
| return new class extends Migration | |||
| { | |||
|     /** | |||
|      * Run the migrations. | |||
|      */ | |||
|     public function up(): void | |||
|     { | |||
|         Schema::create('trabajadors', function (Blueprint $table) { | |||
|             $table->id(); | |||
|             $table->string('nombre'); | |||
|             $table->string('telefono')->nullable(); | |||
|             $table->string('genero'); | |||
|             $table->decimal('sueldo', 10, 2); | |||
|             $table->string('numero_seguro'); | |||
|             $table->string('correo_electronico')->nullable(); | |||
|             $table->unsignedBigInteger('puesto_id'); | |||
|             $table->timestamps(); | |||
|             $table->foreign('puesto_id')->references('id')->on('puestos'); | |||
|         }); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Reverse the migrations. | |||
|      */ | |||
|     public function down(): void | |||
|     { | |||
|         Schema::dropIfExists('trabajadors'); | |||
|     } | |||
| }; | |||
| @ -0,0 +1,31 @@ | |||
| <?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->unsignedBigInteger('puesto_id')->default(1); | |||
|             $table->foreign('puesto_id')->references('id')->on('puestos'); | |||
|         }); | |||
|     } | |||
| 
 | |||
|     /** | |||
|      * Reverse the migrations. | |||
|      */ | |||
|     public function down(): void | |||
|     { | |||
|         Schema::table('users', function (Blueprint $table) { | |||
|             // | |||
|             $table->dropColumn('puesto_id'); | |||
|         }); | |||
|     } | |||
| }; | |||
| @ -0,0 +1,22 @@ | |||
| <?php | |||
| 
 | |||
| use Illuminate\Database\Migrations\Migration; | |||
| use Illuminate\Database\Schema\Blueprint; | |||
| use Illuminate\Support\Facades\Schema; | |||
| 
 | |||
| return new class extends Migration | |||
| { | |||
|     public function up() | |||
|     { | |||
|         Schema::table('trabajadors', function (Blueprint $table) { | |||
|             $table->decimal('sueldo', 12, 2)->change();  // Permite números más grandes con 2 decimales | |||
|         }); | |||
|     } | |||
| 
 | |||
|     public function down() | |||
|     { | |||
|         Schema::table('trabajadors', function (Blueprint $table) { | |||
|             $table->decimal('sueldo', 8, 2)->change();  // Vuelve al tamaño original si necesitas revertir | |||
|         }); | |||
|     } | |||
| }; | |||
| @ -0,0 +1,17 @@ | |||
| <?php | |||
| 
 | |||
| namespace Database\Seeders; | |||
| 
 | |||
| use Illuminate\Database\Console\Seeds\WithoutModelEvents; | |||
| use Illuminate\Database\Seeder; | |||
| 
 | |||
| class AutoSeeder extends Seeder | |||
| { | |||
|     /** | |||
|      * Run the database seeds. | |||
|      */ | |||
|     public function run(): void | |||
|     { | |||
|         // | |||
|     } | |||
| } | |||
| @ -0,0 +1,18 @@ | |||
| <?php | |||
| 
 | |||
| namespace Database\Seeders; | |||
| 
 | |||
| use Illuminate\Database\Console\Seeds\WithoutModelEvents; | |||
| use Illuminate\Database\Seeder; | |||
| use App\Models\Trabajador; | |||
| 
 | |||
| class TrabajadorSeeder extends Seeder | |||
| { | |||
|     /** | |||
|      * Run the database seeds. | |||
|      */ | |||
|     public function run(): void | |||
|     { | |||
|          | |||
|     } | |||
| } | |||
| @ -0,0 +1,77 @@ | |||
| @extends('layouts.plantilla') | |||
| 
 | |||
| @section('contenido') | |||
|     <div class="container"> | |||
|         <div class="row"> | |||
|             <div class="col-md-12"> | |||
|                 <h1>Autos</h1> | |||
|             </div> | |||
|             <div class="row"> | |||
|                 <div class="col-md-12"> | |||
|                     <a href="{{ route('autos.create') }}" class="btn btn-primary">Agregar Auto</a> | |||
|                     <table class="table table-striped"> | |||
|                         <thead> | |||
|                             <tr> | |||
|                                 <th>Marca</th> | |||
|                                 <th>Modelo</th> | |||
|                                 <th>Año</th> | |||
|                                 <th>Color</th> | |||
|                                 <th>Precio</th> | |||
|                             </tr> | |||
|                         </thead> | |||
|                         <tbody> | |||
|                             @foreach ($autos as $auto) | |||
|                                 <tr> | |||
|                                     <td>{{ $auto->marca }}</td> | |||
|                                     <td>{{ $auto->modelo }}</td> | |||
|                                     <td>{{ $auto->año }}</td> | |||
|                                     <td>{{ $auto->color }}</td> | |||
|                                     <td>{{ $auto->precio }}</td> | |||
|                                     <td> | |||
|                                         <a href="{{ route('autos.edit', $auto->id) }}" class="btn btn-warning">Editar</a> | |||
|                                         <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#confirmDeleteModal" data-id="{{ $auto->id }}"> | |||
|                                             Eliminar | |||
|                                         </button> | |||
|                                     </td> | |||
|                                 </tr> | |||
|                             @endforeach | |||
|                         </tbody> | |||
|                     </table> | |||
|                 </div> | |||
|             </div> | |||
|         </div> | |||
|     </div> | |||
| 
 | |||
|     <!-- Modal --> | |||
|     <div class="modal fade" id="confirmDeleteModal" tabindex="-1" aria-labelledby="confirmDeleteModalLabel" aria-hidden="true"> | |||
|         <div class="modal-dialog"> | |||
|             <div class="modal-content"> | |||
|                 <div class="modal-header"> | |||
|                     <h5 class="modal-title" id="confirmDeleteModalLabel">Confirmar Eliminación</h5> | |||
|                     <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | |||
|                 </div> | |||
|                 <div class="modal-body"> | |||
|                     ¿Estás seguro de que deseas eliminar este auto? | |||
|                 </div> | |||
|                 <div class="modal-footer"> | |||
|                     <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button> | |||
|                     <form id="deleteForm" action="" method="POST" style="display:inline;"> | |||
|                         @csrf | |||
|                         @method('DELETE') | |||
|                         <button type="submit" class="btn btn-danger">Sí, eliminar</button> | |||
|                     </form> | |||
|                 </div> | |||
|             </div> | |||
|         </div> | |||
|     </div> | |||
| 
 | |||
|     <script> | |||
|         var confirmDeleteModal = document.getElementById('confirmDeleteModal'); | |||
|         confirmDeleteModal.addEventListener('show.bs.modal', function (event) { | |||
|             var button = event.relatedTarget; | |||
|             var autoId = button.getAttribute('data-id'); | |||
|             var form = document.getElementById('deleteForm'); | |||
|             form.action = '/autos/' + autoId; | |||
|         }); | |||
|     </script> | |||
| @endsection | |||
| @ -0,0 +1,49 @@ | |||
| @extends('layouts.plantilla') | |||
| 
 | |||
| @section('contenido') | |||
|     <div class="content"> | |||
|         <div class="row"> | |||
|             <div class="col-12 pt-5"> | |||
|                 @if($auto) | |||
|                     <h1>Editar Auto</h1> | |||
|                 @else | |||
|                     <h1>Crear Auto</h1> | |||
|                 @endif | |||
|             </div> | |||
| 
 | |||
|             <div class="col-12"> | |||
|                 @if($auto) | |||
|                     <form action="{{ route('autos.update', $auto->id) }}" method="POST"> | |||
|                         @csrf | |||
|                         @method('PUT') | |||
|                 @else | |||
|                     <form action="{{ route('autos.store') }}" method="POST"> | |||
|                         @csrf | |||
|                 @endif | |||
|                     <div class="form-group"> | |||
|                         <label for="marca" class="form-label">Marca</label> | |||
|                         <input type="text" class="form-control" id="marca" name="marca" value="{{$auto ? $auto->marca : ''}}" placeholder="Ingrese la marca" pattern="[A-Za-z\s]+" title="Solo letras y espacios" required> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="modelo" class="form-label">Modelo</label> | |||
|                         <input type="text" class="form-control" id="modelo" name="modelo" value="{{$auto ? $auto->modelo : ''}}" placeholder="Ingrese el modelo" pattern="[A-Za-z\s]+" title="Solo letras y espacios" required> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="año" class="form-label">Año</label> | |||
|                         <input type="number" class="form-control" id="año" name="año" value="{{$auto ? $auto->año : ''}}" placeholder="Ingrese el año" required> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="color" class="form-label">Color</label> | |||
|                         <input type="color" class="form-control" id="color" name="color" value="{{$auto ? $auto->color : '#000000'}}" required> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="precio" class="form-label">Precio</label> | |||
|                         <input type="number" step="0.01" class="form-control" id="precio" name="precio" value="{{$auto ? $auto->precio : ''}}" placeholder="Ingrese el precio" required> | |||
|                     </div> | |||
|                     <button type="submit" class="btn btn-primary">Guardar</button> | |||
|                     <a href="{{ route('autos.index') }}" class="btn btn-danger">Cancelar</a> | |||
|                 </form> | |||
|             </div> | |||
|         </div> | |||
|     </div> | |||
| @endsection | |||
| @ -0,0 +1,49 @@ | |||
| @extends('layouts.plantilla') | |||
| 
 | |||
| @section('contenido') | |||
|     <div class="container"> | |||
|         <div class="row"> | |||
|             <div class="col-md-12"> | |||
|                 <h1>Trabajadores</h1> | |||
|             </div> | |||
|             <div class="row"> | |||
|                 <div class="col-md-12"> | |||
|                     <a href="{{ route('trabajadores.create') }}" class="btn btn-primary">Agregar Trabajador</a> | |||
|                     <table class="table table-striped"> | |||
|                         <thead> | |||
|                             <tr> | |||
|                                 <th>Nombre</th> | |||
|                                 <th>Teléfono</th> | |||
|                                 <th>Género</th> | |||
|                                 <th>Sueldo</th> | |||
|                                 <th>Puesto</th> | |||
|                                 <th>Número de Seguro</th> | |||
|                                 <th>Correo Electrónico</th> | |||
|                                 <th>Acciones</th> | |||
|                             </tr> | |||
|                         </thead> | |||
|                         <tbody> | |||
|                             @foreach ($trabajadores as $trabajador) | |||
|                                 <tr> | |||
|                                     <td>{{ $trabajador->nombre }}</td> | |||
|                                     <td>{{ $trabajador->telefono }}</td> | |||
|                                     <td>{{ $trabajador->genero }}</td> | |||
|                                     <td>{{ $trabajador->sueldo }}</td> | |||
|                                     <td>{{ $trabajador->Puesto->nombre }}</td> | |||
|                                     <td>{{ $trabajador->numero_seguro }}</td> | |||
|                                     <td>{{ $trabajador->correo_electronico }}</td> | |||
|                                     <td> | |||
|                                         <a href="{{ route('trabajadores.edit', $trabajador->id) }}" class="btn btn-warning">Editar</a> | |||
|                                         <form action="{{ route('trabajadores.destroy', $trabajador->id) }}" method="POST"> | |||
|                                             @csrf | |||
|                                             @method('DELETE') | |||
|                                             <button type="submit" class="btn btn-danger">Eliminar</button> | |||
|                                         </form> | |||
|                                     </td> | |||
|                                 </tr> | |||
|                             @endforeach | |||
|                         </tbody> | |||
|                     </table> | |||
|                 </div> | |||
|             </div> | |||
|         @endsection | |||
| @ -0,0 +1,66 @@ | |||
| @extends('layouts.plantilla') | |||
| 
 | |||
| @section('contenido') | |||
|     <div class="content"> | |||
|         <div class="row"> | |||
|             <div class="col-12 pt-5"> | |||
|                 @if($trabajador) | |||
|                     <h1>Editar Trabajador</h1> | |||
|                 @else | |||
|                     <h1>Crear Trabajador</h1> | |||
|                 @endif | |||
|             </div> | |||
| 
 | |||
|             <div class="col-12"> | |||
|                 @if($trabajador) | |||
|                     <form action="{{ route('trabajadores.update', $trabajador->id) }}" method="POST"> | |||
|                         @csrf | |||
|                         @method('PUT') | |||
|                 @else | |||
|                     <form action="{{ route('trabajadores.store') }}" method="POST"> | |||
|                         @csrf | |||
|                 @endif | |||
|                     <div class="form-group"> | |||
|                         <label for="nombre" class="form-label">Nombre</label> | |||
|                         <input type="text" class="form-control" id="nombre" name="nombre" value="{{$trabajador ? $trabajador->nombre : ''}}" placeholder="Ingrese el nombre" required> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="telefono" class="form-label">Teléfono</label> | |||
|                         <input type="text" class="form-control" id="telefono" name="telefono" value="{{$trabajador ? $trabajador->telefono : ''}}" placeholder="Ingrese el teléfono"> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="genero" class="form-label">Género</label> | |||
|                         <select name="genero" id="genero" class="form-control"> | |||
|                             <option value="Masculino" {{$trabajador ? ($trabajador->genero == 'Masculino' ? 'selected' : '') : ''}}>Masculino</option> | |||
|                             <option value="Femenino" {{$trabajador ? ($trabajador->genero == 'Femenino' ? 'selected' : '') : ''}}>Femenino</option> | |||
|                             <option value="Otro" {{$trabajador ? ($trabajador->genero == 'Otro' ? 'selected' : '') : ''}}>Otro</option> | |||
|                         </select> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="sueldo" class="form-label">Sueldo</label> | |||
|                         <input type="number" step="0.01" class="form-control" id="sueldo" name="sueldo" value="{{$trabajador ? $trabajador->sueldo : ''}}" placeholder="Ingrese el sueldo" required> | |||
|                     </div> | |||
|                         <div class="form-group"> | |||
|                         <label for="puesto" class="form-label">Puesto</label> | |||
|                         <select name="puesto_id" id="puesto" class="form-control"> | |||
|                             @foreach($puestos as $puesto) | |||
|                                 <option value="{{$puesto->id}}" {{$trabajador ? ($trabajador->puesto_id == $puesto->id ? 'selected' : '') : ''}}>{{$puesto->nombre}}</option> | |||
|                             @endforeach | |||
|                         </select> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="numero_seguro" class="form-label">Número de Seguro</label> | |||
|                         <input type="text" class="form-control" id="numero_seguro" name="numero_seguro" value="{{$trabajador ? $trabajador->numero_seguro : ''}}" placeholder="Ingrese el número de seguro" required> | |||
|                     </div> | |||
|                     <div class="form-group"> | |||
|                         <label for="correo_electronico" class="form-label">Correo Electrónico</label> | |||
|                         <input type="email" class="form-control" id="correo_electronico" name="correo_electronico" value="{{$trabajador ? $trabajador->correo_electronico : ''}}" placeholder="Ingrese el correo electrónico"> | |||
|                     </div> | |||
|                     <button type="submit" class="btn btn-primary">Guardar</button> | |||
|                     <a href="{{ route('trabajadores.index') }}" class="btn btn-danger">Cancelar</a> | |||
|                 </form> | |||
|             </div> | |||
|         </div> | |||
|     </div> | |||
|     </div> | |||
| @endsection | |||
					Loading…
					
					
				
		Reference in new issue