laravel 4.2中的Web服务

时间:2016-05-31 11:54:24

标签: laravel

我创建了用于将用户登录到我的应用程序的API,但随后它以else部分作为响应进行响应

  

{"错误":true,"消息":"检查您的用户名或密码"}

下面是我的控制器

public function getLogin()
{
    $user = array(
            'username' => Input::get('username'),
            'password' => Input::get('password')
        );

      if (Auth::attempt($user))
         {
            $user = User::find(Auth::user()->id);
            $role = $user->roles;
                if ($role[0]->name == 'Customer')
                {
                   return Response::json(['error' => false, 'message' => 'Customer Logged in successfully', "user"=>$user]);
                }
                else
                 {
                  return Response::json(['error'=>true, 'message'=>'Check your login details']);
                 }

         }
      else
        {
            return Response::json(['error' => true, 'message' => 'Check your username or password']);
        }
}

0 个答案:

没有答案