71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?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);
|
|
}
|
|
}
|