简体   繁体   English

在laravel5.4中以admin身份显示所有用户

[英]Show All Users as admin in laravel5.4

I login as Admin in laravel and want see all users that are in users table,I used Rapid Authentication to login admin,my admin\\login controller has this code: 我在laravel中以管理员身份登录,并希望查看用户表中的所有用户,我使用了快速身份验证登录管理员,我的admin \\ login控制器具有以下代码:

 use AuthenticatesUsers;

protected $redirectTo = 'admin/home';

public function __construct()
{
    $this->middleware('guest:admin')->except('logout');
}

public function showLoginForm()
{
    return view('admin.login');
}
protected function guard()
{
    return Auth::guard('admin');
}

I Want in admin\\home page I give list of projects and users are in users table,I used this code but say to me that users and projects undefind: 我想要在admin \\ home页面中提供项目列表,并且用户位于users表中,我使用了此代码,但对我说,用户和项目未定义:

<div class="text-muted text-size-small">{{$users()->count()}}</div>

<div class="text-muted text-size-small">{{$projects()->count()}}</div>

How I can send Users and projects object to this view,that when admin login see their count? 如何将用户和项目对象发送到此视图,以便管理员登录时可以查看其计数?

The reason why you get an undefined error is because you did not send user and project data to view. 出现未定义错误的原因是因为您没有发送用户和项目数据进行查看。

Let's say you have an AdminHomeController with a method that returns a view 假设您有一个带有返回视图的方法的AdminHomeController

//Your route should look like this

    Route::get('admin/home','AdminHomeController@showUsers');

class AdminHomeController extends Controller {

    //AdminHomeController
        public function showUsers(){

        $users =User::all(); //get all users
    $projects =Project::all(); //get all projects


        return view('admin.home',['users'=>$users,'projects'=>$projects]); //send users and projects to view
        }
}

Do have a look at laravel official documentation 看看laravel官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM