1

i have one problem, and I cant solve it.

In my controller i have method:

public function deleteImg(Request $request, $id) {
        $image_id  = $request->input('imgId');
        $image_src = $request->input('imgSrc');
        AdImages::delete($id, $image_id, $image_src);
    }

Inside of AdImages class I have static method:

public static function delete($id, $image_id, $image_src) {
    return response()->json(['status' => 'error', 'message' => 'Error occurred. Please try again.']);
}

And here is ajax:

$.ajax({
            url: '/dashboard/ad/{{ $ad->id }}/remove-image',
            type: 'POST',
            data: {imgId: imgId, imgSrc: imgSrc},
            success: function(data) {
                console.log(data);
            }
        })

Problem is if i return response i got nothing, empty string. But if i var dump(response()->...) i see object i need.

Any ideas/suggestions ?

Thank you

1
  • Instead of return response()->json(['status' => 'error', 'message' => 'Error occurred. Please try again.']) do echo that array Commented Jun 6, 2016 at 19:30

3 Answers 3

3

Your controller method isn't actually returning anything to the browser. You should put the return json response call in your controller method, not in your model.

I'd also advise you not to name model methods "delete", as that's an Eloquent keyword.

Sign up to request clarification or add additional context in comments.

Comments

1

Add a return to AdImages call:

return AdImages::delete($id, $image_id, $image_src);

Comments

0

thank you guys. that was the problem :)

And yes, it would be smart to rename delete to something else.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.