I hope that the front end can receive the data returned by the controller after the post, how can I do it?
const submit = () => {
router.post(route('searches.store'),{'keyword':keyword.value,'type':tab.value},).then((res) => {
console.log(res.data)
})
};
public function store(Request $request)
{
if ($request->input('type', 'comic') == 'comic') {
$data = Comic::query()->where('name', 'like', '%'.$request->input('keyword').'%')->with(['reader:id,name'])->take(30)->get();
}
return redirect()->back()->with('data', $data);
}
First of all your $data variable is defined inside an if statement. If the statement isn't true, then you'll have an issue.
Second, I assume you are wanting a json response rather than a redirect. Try
return response()->json([
'data' => $data
], 200);
@Ben Taylor
``
All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.
{"data":"111"}
Please or to participate in this conversation.