RSander
RSander

Reputation: 25

how to create a custom store method using backpack V4

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

Upvotes: 1

Views: 1890

Answers (1)

romulos
romulos

Reputation: 268

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

Upvotes: 1

Related Questions