2

I followed a tutorial on Laravel and AngularJS and trying to convert a public function to laravel 5. The code is this:

public function store()
    {
        Comment::create(array(
            'author' => Input::get('author'),
            'text' => Input::get('text')
        ));

        return Response::json(array('success' => true));
    }

I converted it with this:

public function store()
    {
        Comment::create(array(
            'author' => Request::get('author'),
            'text' => Request::get('text')
        ));
    }

Now, how about the line return Response::json(array('success' => true))? How can I convert it to Laravel 5? Thank you.

1
  • 2
    In laravel 5 if you just return an array it will show up in output as json, so just return array('success' => true); would do. Commented Sep 26, 2015 at 5:22

1 Answer 1

4

Not sure what you mean by converting to Laravel 5, this line of code itself is valid Laravel 5 code, but you can leverage nice helper function Laravel 5 provides:

return response()->json([
    'success' => true
]);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.