0

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.

2 Answers 2

1

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!

4
  • I used dd in Advert Controller.php and it was a mistake.
    – neuroine
    Oct 21, 2016 at 12:47
  • It is possible to pass the coordinates from crop to store/update method?
    – neuroine
    Oct 21, 2016 at 12:53
  • Not currently, no. But if you do know the coordinates and they stay the same, you should probably be cropping inside the model, in a mutator. That way, any time the image gets uploaded (no matter where from - CRUD or front-end), it will use the same cropping rules. laravel-backpack.readme.io/docs/crud-fields#image
    – tabacitu
    Oct 21, 2016 at 14:09
  • When I add new photo it works fine, but when I get existing file url or base64, photo show up without all controls. Displays only 'Choose file' and trash button.
    – neuroine
    Oct 27, 2016 at 22:34
0

It looks like you should move your logic from store and edit methods to the mutators.

Take a look at this package. It contains the basic logic from the example and comes in handy when dealing with images.

Can't help with the dimensions and stuff :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.