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.4 KiB

<?php
namespace App\Http\Controllers;
use App\Models\Chofer;
use Illuminate\Http\Request;
use PDF;
use App\Exports\ChoferesExport;
use Maatwebsite\Excel\Facades\Excel;
class ChoferController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$choferes = Chofer::all();
return view('choferes', compact('choferes'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('choferesCrearEditar', ['chofer' => null]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate([
'nombre' => 'required|string|max:255',
'tipo_licencia' => 'required|string|max:255',
]);
Chofer::create($request->all());
return redirect()->route('choferes.index')->with('success', 'Chofer creado exitosamente.');
}
/**
* Display the specified resource.
*/
public function show(Chofer $chofer)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$chofer = Chofer::findOrFail($id);
return view('choferesCrearEditar', compact('chofer'));
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->validate([
'nombre' => 'required|string|max:255',
'tipo_licencia' => 'required|string|max:255',
]);
$chofer = Chofer::findOrFail($id);
$chofer->update($request->all());
return redirect()->route('choferes.index')->with('success', 'Chofer actualizado exitosamente.');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$chofer = Chofer::findOrFail($id);
$chofer->delete();
return redirect()->route('choferes.index')->with('success', 'Chofer eliminado exitosamente.');
}
public function exportExcel()
{
return \Maatwebsite\Excel\Facades\Excel::download(new \App\Exports\ChoferesExport, 'choferes.xlsx');
}
public function exportPDF()
{
$choferes = \App\Models\Chofer::all();
$pdf = \PDF::loadView('exports.choferes-pdf', ['choferes' => $choferes]);
return $pdf->download('choferes.pdf');
}
}