I have the following controller:
public function show($id)
{
// Busco el perfil
$perfil = lista::where('di', $id)->first();
//con el resultado de la busqueda muestro el perfil
$mostrarperfil = Perfiles::where('id', $perfil['di'])->get();
return view('products.show', compact('mostrarperfil'));
}
This driver works correctly for me, but what I need is to do this but with several profiles at the same time, let's see if I understand myself. I want to change this:
$perfil = lista::where('di', $id)->first();
For this:
$perfil = lista::where('di', $id)->get();
This would give me several results but I don't know what changes I would have to make to it to be able to show all the profiles that $profile throws at me:
$mostrarperfil = Perfiles::where('id', $perfil['di'])->get();
I hope you understand, I tried to do a foreach but I can't do it, also I don't know if it's the correct way..
I'm trying to do it in the following way but it keeps showing me a single result..
public function show($id)
{
// Busco el perfil
$perfil = lista::where('di', $id)->get();
foreach($perfil as $perfi){
//con el resultado de la busqueda muestro el perfil
$mostrarperfil = Perfiles::where('id', $perfi->di)->get();
}
return view('products.show', compact('mostrarperfil'));
}
In your List model you must add the relationship it has with the profile, assuming that a list belongs to a profile (one to one):
then in your query you should use with:
It will return an object that in its attributes will have one called profile that will be an array of objects from the profile table.