Why does you Controller respond with a Redirect at all? You can return 20x with a JSON payload.
Jun 13, 2023
7
Level 1
Inertia detect api request 303 in nuxt js and laravel
I have a challenge in the code below how can be able to detect response in my index component approve method from my lender controller so that I could be able to set the loading to false again if the API request is successful which is the status of API request is 303 and the onSuccess in inertia it will detect status 200. What are your insights to solve my problem?
Here is my index component with approve method:
approve(marketLocation) {
this.loading = true;
this.$inertia.patch(
this.$route("admin.marketLocation.approve", { id: marketLocation.id }),
{
preserveState: true,
onSuccess: (response) => {
console.log("Success:", response);
this.loading = false;
},
onError: (error) => {
console.log("Error:", error);
this.loading = false;
},
}
);
},
Here is my lender controller:
public function approve($id)
{
$lenderMarketLocation = $this->fetchLenderMarketLocation($id);
if ($this->canBeApproved($lenderMarketLocation)) {
$this->approveMarketLocation($lenderMarketLocation);
$this->sendApprovalNotification($lenderMarketLocation);
$this->saveLenderMarketLocation($lenderMarketLocation);
}
$message = 'Market location approved.';
return redirect()->back()->with('message', $message);
}
Please or to participate in this conversation.