baig772 baig772 - 2 months ago 16
reST (reStructuredText) Question

Write web services with existing Laravel Controllers

I have a project in

Laravel 5.2
and now I have to make the
APIs
for that. I tried to hit the
localhost/myproject/login
via postman as a post request with the parameters but it returns me the
HTML
in return. I have used Laravel's auth scaffolding for the authorization.
I am unable to find
postLogin
function in my project.
I have separated the routes but how can I change the existing functions for the API?

Route::group(array('prefix' => 'api/v1'), function()
{
Route::post('login', 'AuthController@postLogin');
});

Answer

Here is the postLogin that returns the json rather than the html code.

public function authenticate()
{
    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        // Authentication passed...
        //return redirect()->intended('dashboard');
        return response()->json(['status' => 1]);
    }
}

If you have any trouble, let me know.

Comments