Hello,
I started using server fetched partials so I am returning the same view, with the same data passed to that view from several controller methods.
For example:
// In the controller
public function create(Request $request)
{
// do some create stuff
// then get the partial data and return it
$data = DB::table('table')->....->get();
return view('_some_partial', ['data' => '$data']);
}
public function edit(Request $request)
{
// do some edit stuff
// then get the partial data and return it
$data = DB::table('table')->....->get();
return view('_some_partial', ['data' => '$data']);
}
public function delete(Request $request)
{
// do some delete stuff
// then get the partial data and return it
$data = DB::table('table')->....->get();
return view('_some_partial', ['data' => '$data']);
}
I could do something like that - create a function inside the same controller that calls only the part related to the partial and call it from within the relevant controller methods(didn't try yet):
public function return_some_partial()
{
$data = DB::table('table')->....->get();
return view('_some_partial', ['data' => '$data']);
}
and call it from the other methods:
public function create(Request $request)
{
// do some create stuff
$this->return_some_partial();
}
Is it OK? Will it work? Or there is a better way to do it? It just feels that such function does not "belong" to a Controller
Thanks