Answer the question
In order to leave comments, you need to log in
How to call a function with Request from under the controller?
Good afternoon, there is a function with which I get a list through Ajax
public function get(Request $request)
{
$lists = DB::table('lists')->where('user_id', $this->__user_id)->get();
return json_encode($lists);
}
public function index()
{
$lists = $this->get();
return view('lists', ['lists' => $lists]);
}
Answer the question
In order to leave comments, you need to log in
pass null as an argument.
Better yet, move the shared code into another method, and then call it via get(); and through index();
public function get(Request $request)
Remove Request $request , because you don't use it anywhere.
If used, take it in index() and pass the instance to the get function.
If it is not possible to receive it in index(), but it is required in get() - create a new instance of the Request class, fill it with the necessary or dummy data, and pass it.
A bunch of options. It all depends on the implementation and your code.
If the parts of the code in the question are not fictitious, but real, the first option will suit you. Remove Request.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question