You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					97 lines
				
				2.9 KiB
			
		
		
			
		
	
	
					97 lines
				
				2.9 KiB
			| 
								 
											8 months ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace App\Http\Controllers;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use App\Models\TiposLicencias;
							 | 
						||
| 
								 | 
							
								use Illuminate\Http\Request;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class TiposLicenciasController extends Controller
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Display a listing of the resource.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function index(Request $request)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $busqueda = $request->busqueda;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if($busqueda) {
							 | 
						||
| 
								 | 
							
								        $tiposLicencias = TiposLicencias::where('nombre', 'LIKE', "%{$busqueda}%")->get();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if($tiposLicencias->count() == 0) {
							 | 
						||
| 
								 | 
							
								            return redirect()->route('tiposLicencias.index')
							 | 
						||
| 
								 | 
							
								                           ->with('error', 'No existe ningún tipo de licencia con el nombre "' . $busqueda . '". Por favor, inténtalo de nuevo.');
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // Si solo hay un tipo de licencia, mostrar sus detalles
							 | 
						||
| 
								 | 
							
								        if($tiposLicencias->count() == 1) {
							 | 
						||
| 
								 | 
							
								            $tipoLicencia = $tiposLicencias->first();
							 | 
						||
| 
								 | 
							
								            return redirect()->route('tiposLicencias.edit', $tipoLicencia->id);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // Si hay múltiples coincidencias, mostrar la lista filtrada
							 | 
						||
| 
								 | 
							
								        return view('tiposLicencias', ["tiposLicencias" => $tiposLicencias]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // Si no hay búsqueda, mostrar todos los tipos de licencias
							 | 
						||
| 
								 | 
							
								        $tiposLicencias = TiposLicencias::all();
							 | 
						||
| 
								 | 
							
								        return view('tiposLicencias', ["tiposLicencias" => $tiposLicencias]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Show the form for creating a new resource.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function create()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $tiposLicencias = TiposLicencias::all();
							 | 
						||
| 
								 | 
							
								        return view('tiposLicenciasCrearEditar',['tiposLicencias'=>$tiposLicencias]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Store a newly created resource in storage.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function store(Request $request)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $tipoLicencia = new TiposLicencias($request->all());
							 | 
						||
| 
								 | 
							
								        $tipoLicencia->save();
							 | 
						||
| 
								 | 
							
								        return redirect()->route('tiposLicencias.index')->with('success', 'Tipo de licencia creado exitosamente.');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Display the specified resource.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function show(TiposLicencias $tipoLicencia)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        //
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Show the form for editing the specified resource.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function edit($id)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $tipoLicencia = TiposLicencias::find($id);
							 | 
						||
| 
								 | 
							
								        return view('tiposLicenciasCrearEditar',['tipoLicencia'=>$tipoLicencia]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Update the specified resource in storage.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function update(Request $request, $id)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $tipoLicencia = TiposLicencias::find($id);
							 | 
						||
| 
								 | 
							
								        $tipoLicencia->fill($request->all());
							 | 
						||
| 
								 | 
							
								        $tipoLicencia->save();
							 | 
						||
| 
								 | 
							
								        return redirect()->route('tiposLicencias.index')->with('success', 'Tipo de licencia actualizado exitosamente.');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Remove the specified resource from storage.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function destroy($id)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $tipoLicencia = TiposLicencias::find($id);
							 | 
						||
| 
								 | 
							
								        $tipoLicencia->delete();
							 | 
						||
| 
								 | 
							
								        return redirect()->route('tiposLicencias.index')->with('success', 'Tipo de licencia eliminado exitosamente.');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |