|
|
@ -11,33 +11,28 @@ class MarcaController extends Controller |
|
|
|
/** |
|
|
|
* Display a listing of the resource. |
|
|
|
*/ |
|
|
|
public function index(Request $request) |
|
|
|
{ |
|
|
|
$busqueda = $request->busqueda; |
|
|
|
|
|
|
|
if ($busqueda) { |
|
|
|
$marcas = Marca::where('nombre', 'LIKE', "%{$busqueda}%")->get(); |
|
|
|
|
|
|
|
if ($marcas->count() == 0) { |
|
|
|
return redirect()->route('marca.index') |
|
|
|
->with('error', 'No existe ninguna marca con el nombre "' . $busqueda . '". Por favor, inténtalo de nuevo.'); |
|
|
|
public function index(Request $request) |
|
|
|
{ |
|
|
|
$busqueda = $request->busqueda; |
|
|
|
|
|
|
|
if ($busqueda) { |
|
|
|
// Busca en la tabla 'marcs' usando la relación |
|
|
|
$marcas = Marca::whereHas('Marc', function($query) use ($busqueda) { |
|
|
|
$query->where('name', 'LIKE', "%{$busqueda}%"); |
|
|
|
})->get(); |
|
|
|
|
|
|
|
if ($marcas->isEmpty()) { |
|
|
|
return redirect()->route('marca.index') |
|
|
|
->with('error', 'No existe ninguna marca con el nombre "' . $busqueda . '". Por favor, inténtalo de nuevo.'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// Si no hay búsqueda, mostrar todas las marcas |
|
|
|
$marcas = Marca::all(); |
|
|
|
} |
|
|
|
|
|
|
|
// Si solo hay una marca, mostrar sus detalles |
|
|
|
if ($marcas->count() == 1) { |
|
|
|
$marca = $marcas->first(); |
|
|
|
return redirect()->route('marca.edit', $marca->id); |
|
|
|
} |
|
|
|
|
|
|
|
// Si hay múltiples coincidencias, mostrar la lista filtrada |
|
|
|
return view('marcas', ["marcas" => $marcas]); |
|
|
|
return view('marcas', ['marcas' => $marcas]); |
|
|
|
} |
|
|
|
|
|
|
|
// Si no hay búsqueda, mostrar todas las marcas |
|
|
|
$marcas = Marca::all(); |
|
|
|
return view('marcas', ["marcas" => $marcas]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Show the form for creating a new resource. |
|
|
|
*/ |
|
|
|