Kezern
Kezern

Reputation: 473

Backpack V4 modifying field before store

In 3.6 version of backpack I can change an attribute value before storing it. I have this code

If ($request->description == "") {
    $request->description="User has not entered any description";
}
$redirect_location = parent::storeCrud($request);

What can I do to get the same in V4? I'm reading this guide but I can't make it to work. This is what I'm trying in V4

public function store(PedidoRequest $request)
{
    Log::debug('testing...');



    If ($request->description == "") {
       $request->description="User has not entered any description";
    }

    $redirect_location = $this->traitStore();
    return $redirect_location;
}

Upvotes: 2

Views: 980

Answers (1)

lagbox
lagbox

Reputation: 50561

The Request object in Laravel, Illuminate\Http\Request, doesn't have the ability to set the inputs via the properties like that, no __set method ($request->description = '...' does not set an input named description). You would have to merge the inputs into the request or use the array syntax to do that:

$request->merge(['description' => '...']);
// or
$request['description'] = '...';

But since backpack seems to have abstracted things apparently you aren't controlling anything in your controller methods you could try this:

$this->crud->request->request->add(['description'=> '...']);

Potentially:

$this->request->merge(['description' => '...']);

That would be assuming some trait the Controller uses is using the Fields trait.

Upvotes: 3

Related Questions