1

What is the Laravel 5 equivelant for Laravel 4s?:

Response::json
Response::input

And what facade do I need to use?

2 Answers 2

2

Inject the ResponseFactory into your class/method:

<?php namespace App;

use Illuminate\Contracts\Routing\ResponseFactory;

class SomeClass {

    protected $response;

    public function __construct(ResponseFactory $response)
    {
        $this->response = $response;
    }

    public function someMethod()
    {
        return $this->response->json($data);
    }
}

Or:

// This will only work if method is resolved by service container
public function someMethod(ResponseFactory $response)
{
    return $response->json($data);
}

You can find a map of Laravel façades and what to type-hint instead at http://laravel.com/docs/master/facades#facade-class-reference

Alternative, you can still use façades, you just need to import them:

<?php namespace App;

use Response;

class SomeClass {

    public function someMethod()
    {
        return Response::json($data);
    }
}

But I’d recommend going the injecting-contracts routes. It’s just a better approach.

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

Comments

0

Response::json() ----> response()->json(['key'=>'value'])

laravel 4.2 way works too btw.

Response::input() (?) [input should be in request] ----> Request::input()

here also, you can Input facade. In practice, not much changed in L5 as long as facades are concerned.

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.