Php 如何获取数组laravel 4的值?

Php 如何获取数组laravel 4的值?,php,laravel,laravel-4,eloquent,Php,Laravel,Laravel 4,Eloquent,我只是想问,我如何用Laravel4得到这段代码的值 $auth = DB::select( 'SELECT auth FROM users WHERE username like ?' , array($username) ); 当我显示代码的结果时,它回显“Array”,并且总是将用户重定向到“anotherpage”,我实际上是这样做的: if (Auth::attempt($userdata)) { if ($auth==0) { ret

我只是想问,我如何用Laravel4得到这段代码的值

$auth = DB::select(
    'SELECT auth FROM users WHERE username like ?'
    , array($username)
);
当我显示代码的结果时,它回显“Array”,并且总是将用户重定向到“anotherpage”,我实际上是这样做的:

if (Auth::attempt($userdata))
{
    if ($auth==0)
    {
        return Redirect::to('home');
    }
    elseif ($auth==1)
    {
        return Redirect::to('dashboard');
    } 
    else 
    {
        return Redirect::to('anotherpage');
    }
}

请帮忙。先谢谢你

当您尝试回显阵列时会发生这种情况。改用。它打印数组(或变量)内容的可读输出:

这样,您将看到数组的内容,然后可以显示特定项

将其封装在
标记中将使输出更具可读性:

echo '<pre>';
print_r($myArray);
echo '</pre>';
echo '<pre>', print_r($myArray), '</pre>';
if($auth = 0)   
echo';
打印(myArray);
回声';
或者简单地说:

echo'',打印($myArray),'';

您使用的查询生成器错误。试试这个:

if($auth == 0)  

首先,为什么要通过Auth类和手动选择查询对用户进行两次身份验证<代码>身份验证::尝试就足够了

无论如何,假设您真的想这样做,您的代码工作不正常,因为您在
if
语句中将
$auth
赋值给0;因此:

if(Auth::attempt($userdata)) 
{
  $auth = DB::table('users')->where('username', '=', $username)->first()->auth;//Don't use "LIKE" as it may cause huge security issues.
  if($auth == 0) {
        return Redirect::to('home');
  }
  else if($auth == 1) {
        return Redirect::to('dashboard');
  }
  else {
        return Redirect::to('anotherpage');
  }
}
基本上是这样的:

因此,我将if语句更改为:

您的最终代码应如下所示:
询问代码的问题必须证明对正在解决的问题的最低理解。包括尝试过的解决方案、它们不起作用的原因以及预期结果。另见:这很可能不是Laravel-4特有的。请更具体地说明您的问题所在。这段代码的值是什么?这是有效的,但当我把它放在if语句中时它就不起作用了,先生。我正在尝试获取登录用户的“Auth”列的值。例如,当用户登录时。如果($auth==0,它将首先进行身份验证,然后告诉用户将使用
进入哪个页面。
if(0) //Which is always false
if($auth == 0)  
if(Auth::attempt($userdata)) 
{
  $auth = DB::table('users')->where('username', '=', $username)->first()->auth;//Don't use "LIKE" as it may cause huge security issues.
  if($auth == 0) {
        return Redirect::to('home');
  }
  else if($auth == 1) {
        return Redirect::to('dashboard');
  }
  else {
        return Redirect::to('anotherpage');
  }
}