In my Angular app I created a service:
.factory('Auth', function($http) {
return {
is_authenticated: function() {
return $http.get('/api/users/is_authenticated');
}
}
});
My method in my API backed by Laravel:
public function is_authenticated()
{
if(Auth::check())
{
return Response::json(array('authenticated' => true));
}
return Response::json(array('authenticated' => false));
}
And then in my controller:
Auth.is_authenticated()
.success(function(data) {
$scope.is_authenticated = data.authenticated;
if(data.authenticated)
console.log('yes');
});
When I go to /api/users/is_authenticated
I see nothing on the page, however, when I echo Auth::check()
there is a 1 on the page.
In my view I have a list with ng-show="is_authenticated"
but it's not working.
What am I doing wrong here? I'm failing to see the problem. Why is 'yes'
not being logged to the console?
And yes, I have injected the Auth
service into my controller.