What are best way to call laravel controller actions in async manner as its very easy with .net using async await keywords.
here is .net example
public async Task<ViewResult> Index() {
return View(await GetThingsAsync());
}
does it doable in laravel same way ?
does PHP laravel provide any helper or plugin that can help to call controller actions in async manner and all DB queries in async manner / does eloquent provide support for asynchronous queries
CodePudding user response:
@Phil i have added a spatie/async package to my laravel project solution and changed my controller code like this .
public function indexAsync(Request $request) { $results=null;
$pool = Pool::create();
$pool[] = async(function () {
return Test::all();
})->then(function ($output) {
$this->results=$output;
});
await($pool);
return view('test.index',['results' => $this->results]);
}
I am getting the expected result on view .
does it work as I want or it can't help to achieve multithreading in php
