rappasoft/laravel-boilerplate

Issue with restoring models

JimmyBower opened this issue · 3 comments

I've tried to create a model based on the user model already implemented and working on the Boilerplate, everything is working perfectly, events, services, views, everything, except the restoring button, it sends empty models to the restore function, and I can't find how I can debug it or where the issue is, I will provide the methods that get executed before it failing (also it doesn't fail, it goes through as if everything went ok, but the model is not restored)

Before this line $xyz works fine if i DD it

        <x-utils.form-button
            :action="route('admin.xyz.restore', $xyz)"
            method="patch"
            button-class="btn btn-info btn-sm"
            icon="fas fa-sync-alt"
            name="confirm-item"
        >

Controller, dd deletedXYZ here is an empty XYZ object

        public function update(XYZ $deletedXYZ)
        {
            $this->xyzService->restore($deletedXYZ);
        
            return redirect()->route('admin.xyz.index')
                ->withFlashSuccess(__('The XYZ was successfully restored.'));
        }

Service

        public function restore(XYZ $xyz): XYZ
        {
          if ($xyz->restore()) {
              event(new XYZRestored($xyz));
        
              return $xyz;
          }
        
          throw new GeneralException(__('There was a problem restoring this xyz. Please try again.'));
        }

Have you inspected the html generated by the route call and if is it correct?
<p>{{route('admin.xyz.restore',$xyz)}}</p>

Ok, I found the issue, it was mainly in the routing variable name (in the route itself), so the route was ok, but variable in route was "xyz" and "deletedXYZ" in controller, but then i got another issue, it can't fetch the resource directly through "XYZ $deletedXYZ" in the update in controller, i have to fetch its id instead and get it using "XYZ::withTrashed()->find($id);", but seems the user model is working without this extra line, can you please explain what maybe missing?

Closing due to inactivity.