Follow these Steps
1. In route file.
Route::get('/useronline', 'HomeController@useronline')->name('useronline');
2. In HomeController
<?php
namespace App\Http\Controllers;
use App\user;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function __construct(){ $this->middleware('auth'); }
public function useronline()
{
$users = User::all();
return view('useronline',compact('users'));
}
public function isOnline()
{
return Cache::has('user-is-online-'. $this->id);
}
}
3. View: useronline.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Online users</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td> @if ($user->isOnline())
<li class="text-success"> Online </li>
@else
<li class="text-muted"> Offline </li>
@endif </td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endsection
1. In route file.
Route::get('/useronline', 'HomeController@useronline')->name('useronline');
2. In HomeController
<?php
namespace App\Http\Controllers;
use App\user;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function __construct(){ $this->middleware('auth'); }
public function useronline()
{
$users = User::all();
return view('useronline',compact('users'));
}
public function isOnline()
{
return Cache::has('user-is-online-'. $this->id);
}
}
3. View: useronline.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Online users</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td> @if ($user->isOnline())
<li class="text-success"> Online </li>
@else
<li class="text-muted"> Offline </li>
@endif </td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endsection
No comments:
Post a Comment