@joshsalway This is personal preference as to how to handle it. I agree I don’t particularly like a method doing multiple things. You could add another method to your current controller for restoring soft deleted models or another option is to create a CustomerRestoreController and have the update method there for explicitly restoring the customer.
Jul 26, 2020
1
Level 21
How to restore using eloquent, with an api with react? With softdeletes
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$customer = Customer::withTrashed()->findOrFail($id);
if($customer->deleted_at != null) {
$customer->restore();
return response()->json($customer);
}
$customer->first_name = $request->first_name;
$customer->last_name = $request->last_name;
$customer->email = $request->email;
$customer->save();
return response()->json($request);
}
How do I restore a customer? If I'm using an API resource...
With SoftDeletes a deleted_at column is created and only a date is added...
This works is there any way you would improve this?
https://laravel.com/docs/7.x/eloquent#querying-soft-deleted-models
Please or to participate in this conversation.