neuroine neuroine - 1 month ago 38
PHP Question

Laravel-Backpack image field debug

I have a problem with saving one field, how can I debug?

dd
in AdvertController.php has no effect. All other fields are stored properly.

AdvertController.php

class AdvertController extends Controller
{
public function store(Requests\StoreAdvertPostRequest $request)
{
dd($request->input('photo'));
}


AdvertCrudController.php

public function edit($id)
{

$articlePicture = Advert::find($id)->photos[0]->file_name;

$path = 'uploads/photos/' . $articlePicture;

$this->crud->addField([
'name' => 'photo',
'label' => 'Profile Image',
'type' => 'image',
'value' => $path,
'crop' => true,
'aspect_ratio' => 0.75,
]);

return parent::edit($id);
}


Finally, I would also like to pass the coordinates of the crop to store method.

Update 1:

When I add new photo it works fine, but when I get existing file, photo show up without all controls. Displays only 'Choose file' and trash button.

Answer

The "store" method is only called when creating an entry, not editing. Perhaps you were trying to edit? Then the dd() should be placed inside the update() method. But that's in the CrudController, not the regular one. I have no idea what your regular controller does.

Usually when the value does not get stored in the database it's because you forgot to place the column in the $fillable attribute on the model.

Also, because this is an upload field, you should create a mutator that also places the file on disk. The "image" field documentation has it.

Cheers!

Comments