mysql_num_rows 在 laravel 中?

mysql_num_rows in laravel?

我试图在 laravel 中使用 mysql_num_rows,但 laravel 说它与 'raw php'

中的方式不同

example:

$users = DB::table('users')
         ->where('username', '=', $username)
         ->where('password', '=', $password)
         ->get();

what i want to do:

$count = mysql_num_rows($users);

   if($count > 0 ){

      $user->login = $request->login;
      $user->email = $request->email;
      $user->password = $request->password;

      Auth::login($user);
      return redirect("/");
      }else{
         return "datos incorrectos";
      }

what laravel says:

Call to undefined function App\Http\Controllers\Auth\mysql_num_rows()

PD:它不是代码哲学,只是对那个问题做出评论,我不想要像 "u gonna crypt that thing?" 这样的答案,"why not use [insert my faborite ORM]" 只是一个简单的问题,谢谢

您应该使用 count() 而不是使用 mysql_* 函数。它可以链接到 Eloquent, query builder, or collections.

$users_count = DB::table('users')
     ->where('username', '=', $username)
     ->where('password', '=', $password)
     ->count();