Ahora si :)))))))))))))))))
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Promocion;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PromocionController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$promociones = Promocion::all();
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json($promociones);
|
||||
}
|
||||
|
||||
$categorias = $promociones->pluck('categoria')->filter()->unique()->values();
|
||||
|
||||
return view('promos.index', compact('promociones', 'categorias'));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$promocion = Promocion::with('promoQrs')->findOrFail($id);
|
||||
return response()->json($promocion);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'nombre' => 'required|string|max:100',
|
||||
'direccion' => 'required|string|max:150',
|
||||
'lat' => 'nullable|numeric',
|
||||
'lng' => 'nullable|numeric',
|
||||
'contacto' => 'nullable|string|max:100',
|
||||
'descripcion' => 'nullable',
|
||||
'descripcion_lugar' => 'nullable',
|
||||
'categoria' => 'nullable|string|max:50',
|
||||
'imagen' => 'nullable|string|max:200',
|
||||
]);
|
||||
$promocion = Promocion::create($data);
|
||||
return response()->json($promocion, 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$promocion = Promocion::findOrFail($id);
|
||||
$data = $request->validate([
|
||||
'nombre' => 'sometimes|string|max:100',
|
||||
'direccion' => 'sometimes|string|max:150',
|
||||
'lat' => 'nullable|numeric',
|
||||
'lng' => 'nullable|numeric',
|
||||
'contacto' => 'nullable|string|max:100',
|
||||
'descripcion' => 'nullable',
|
||||
'descripcion_lugar' => 'nullable',
|
||||
'categoria' => 'nullable|string|max:50',
|
||||
'imagen' => 'nullable|string|max:200',
|
||||
]);
|
||||
$promocion->update($data);
|
||||
return response()->json($promocion);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$promocion = Promocion::findOrFail($id);
|
||||
$promocion->delete();
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user