-1
Problem solving: In this example, I am returning in the user view, data referring to 2 different tables (Intro, About), which can be retrieved from a @foreach
Example: View user.index
@foreach($intros as $intro) {{$intro->title_intro}} {{$intro->desc_intro}} @endforeach @foreach($abouts $about ) {{$about ->title_about}} {{$about ->desc_about}} @endforeach
User controller:
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Intro; use App\About; class UserController extends Controller
{ public function index() { return view('user.index', [ 'intros' => Intro::paginate(5), 'abouts' => About::paginate(5) ]); } }
return view('caminho.nomeDaView')->with(['info1' => model::metodo($dado), 'info2' => model::metodo($dado2) ... ]);
, and so on– Diego Ananias
Wait, I still can’t understand... Sorry rs after ->with, this 'info1' would refer to what? And after the model:: this part: method($given) would refer to what? Thanks for the help
– Losantosw
info1 refers to the name of the array that you will see in the view, the method, is the po... How much you know of object orientation?
– Diego Ananias
Basic/Intermediate... only, I don’t have much experience with the Aravel I was confused about which method I would call there... Thus, the information is given that the intro variable is undefined Return view('user.index')->with( [ 'intros' => Intro::index($intro), 'abouts' => About:::index($abouts) ]);
– Losantosw
just do it like this:
return view('user.index', ['intros' => Intro::paginate[5],'abouts' => About::paginate[5], 'skills' => Skill::paginate[5]]);
of course can put all this in a variable and pass there also better including. The method is also valid, but, I think so better (pure opinion)– novic
I just tested it here and it worked out that way Virgilio, thank you very much! And Hanania too, for taking a little time to try to help me... :)

– Losantosw