0

I am trying to follow David Mosher's tutorial on going end-to-end with angular JS on youtube: http://www.youtube.com/watch?v=hqAyiqUs93c.

Everything was going fine until I attempted to route the /auth/login and auth/logout urls to the Authentication Service, as seen in the video at about 14:30. When I attempt to login, I receive a 404 Not Found Error. I have tried messing around with the route's URL, but to no avail. I am running locally on MAMP with MySQL and Laravel.

Here's my code for routes.php

Route::get('/', function(){
    return View::make('index');
});

Route::post('/auth/login/', 'AuthController@login');
Route::get('/auth/logout/', 'AuthController@logout');

and my code for AuthController

<?php

class AuthController extends BaseController {
  public function login()
  {
    if(Auth::attempt(array('email' => Input::json('email'), 'password' => Input::json('password'))))
    {
      return Response::json(Auth::user());
    } else {
      return Response::json(array('flash' => 'Invalid username or password'), 500);
    }
  }

  public function logout()
  {
    Auth::logout();
    return Response::json(array('flash' => 'Logged Out!'));
  }

}

lastly, code for authentication service

angular.module("epicApp")
    .factory('AuthenticationService', function($http, $location){
        return{
            login: function(credentials){
                return $http.post("/auth/login/", credentials);
            },
            logout: function(){
                return $http.get("/auth/logout/");
            }
        }
    })
1
  • Can you copy the error url from console? Commented Oct 1, 2013 at 8:42

2 Answers 2

0

The only one problem is you have to replace all /auth/login/ to auth/login and /auth/logout/ to auth/logout in your route and angular script.

So your route should be,

Route::get('/', function(){
    return View::make('index');
});

Route::post('auth/login', 'AuthController@login');
Route::get('auth/logout', 'AuthController@logout');

And js,

angular.module("epicApp")
    .factory('AuthenticationService', function($http, $location){
        return{
            login: function(credentials){
                return $http.post("auth/login", credentials);
            },
            logout: function(){
                return $http.get("auth/logout");
            }
        }
    })
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know if this question still relevant, but you will get a 404 with any HTTP URL if inside the public folder the index file is not a .php. You could just rename the index.html of your angular app.

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.