简体   繁体   中英

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:

 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:

<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

//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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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