0

I know there's already a lot of answers to this question but none of them seems to match to my problem so here it is.

I'm using AngularJS's $http to make a GET request to my Laravel 5.6 controller.

The controller ClientsController looks like :

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use App\Client;

class ClientsController extends Controller
{
    public function activate($id) {
        $client = Client::find($id);
        return $client;
    }

}

where App\Client refers to an existing model.

On route, it looks like :

Route::get('/clients/activate/{id}', 'Admin\\ClientsController@activate');

and the request form angularJS :

$http({
    url: client_url_with_id
    method: "GET"
}).then(function(response) {
    console.log(response.data);
});

It always shows empty. I don't understand why.

5
  • try return response()->json($client) instead of return. Are you sure you are getting 200 response Commented Jun 4, 2018 at 7:39
  • response.status is always 200 but response.data always empty Commented Jun 4, 2018 at 9:05
  • Is the correct $id being passed? does the $client var actually contain anything? Have you tried returning a string to see if this is in the response? Commented Jun 4, 2018 at 9:37
  • what is the result of response instead of response.data? Commented Jun 4, 2018 at 10:05
  • Try setting the dataType specifically to json if you are expecting json. This helped my similar issue yesterday. stackoverflow.com/questions/15205037/… Commented Jun 4, 2018 at 13:30

0

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.