1
votes

I'm trying to create a custom method in backpack version 4 as I had in backpack version 3 but i'm facing an issue when I tried to insert data.

In the upgrade guide

(https://backpackforlaravel.com/docs/4.0/upgrade-guide)

was wrote that I can have my custom method but I've to do some steps before, for example:

Replacing that line:

use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation

for this line:

use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; }

Then, i've created my method:

public function store(StoreRequest $request)
    {
        Log::debug('testing...');
        $redirect_location = $this->traitStore();
        return $redirect_location;
    }

But when I try to carry out the create process, backpack shows an error view

Class App\Http\Controllers\Admin\StoreRequest does not exist

Going back to the previous version (3.6) I saw that requests were renamed for example

use App\Http\Requests\ItemRequest as StoreRequest;

So, I tried to do the same for backpack version 4, but for this try I got an new error

Class App\Http\Controllers\Admin\ItemRequest not found

Can someone support me with this issue? how may I create my custom methods as I had in the previous version (3.6)?

Thank's

1
Try using the same name for type-hinting the request, as the name you've given when loading the request at the top of the file. If at the top you have "use xxx/StoreRequest" you should have "public function store(StoreRequest $request)". Hope it helps. - tabacitu

1 Answers

1
votes

please, try the following:

  • Replace back

use App\Http\Requests\ItemRequest as StoreRequest;

  • to

use App\Http\Requests\ItemRequest;

  • In your method, change the parameter from

public function store(StoreRequest $request)

  • to

public function store(ItemRequest $request)

and now, try to create a new data again