I am building a form in order to both create and edit records.
Since I am using a lot of relational information (tables) from several catalogs and shown in the for as a select box (Select2), I need to retrieve all the data to be shown in those HTML select tags.
So, let's say that in my controller in the create()
method, I call that info like so:
create()
method of MyController.php:
public function create(Token $token){
//Tags
$universities = University::orderBy('name')->get();
$countries = Country::orderBy('name')->get();
$programs = Program::orderBy('name')->get();
//... and many more
return view('my.form.create',[
'universities' => $universities,
'countries' => $countries,
'programs' => $programs,
'token' => $token
]);
}
How do I do to reuse that piece of code //Tags
//Tags
$universities = University::orderBy('name')->get();
$countries = Country::orderBy('name')->get();
$programs = Program::orderBy('name')->get();
//... and many more
in order to reuse it for the, let's say, edit()
method or other ones??