İlk olarak app/config altındaki session.php 'de sürücü kısmını database olarak degiştiriyoruz.
'driver' => 'database',
başlat cmd yaparak önce htdocs dizininize inerek komut satırına ;
php artisan session:table
composer dump-autoload
php artisan migrate
yazıp yeni oluşan sessions adlı databesimizi acıp oluşan id,payload,last_activity alanlarının altına (user_id , int 11 ve Null'a izin ver ) olacak şekilde user_id kısmını ekliyoruz.
Sıra geldi Model dosyası olusturmaya .. ben modelimi online.php olarak tanımladım siz istediginiz adı verebilirsiniz.Model dosyam ;
<?php
use Illuminate\Database\Eloquent\Model;
//use Session;
class Online extends Model {
/**
* {@inheritDoc}
*/
public $table = 'sessions';
/**
* {@inheritDoc}
*/
public $timestamps = false;
/**
* Returns all the guest users.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeGuests($query)
{
return $query->whereNull('user_id');
}
/**
* Returns all the registered users.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRegistered($query)
{
return $query->whereNotNull('user_id')->with('user');
}
/**
* Updates the session of the current user.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUpdateCurrent($query)
{
return $query->where('id', Session::getId())->update(array(
'user_id' => !trim(Auth::user())==false ? Auth::user()->id : null
));
}
/**
* Returns the user that belongs to this entry.
*
* @return \Cartalyst\Sentry\Users\EloquentUser
*/
public function user()
{
return $this->belongsTo('User'); # Sentry 3
// return $this->belongsTo('Cartalyst\Sentry\Users\Eloquent\User'); # Sentry 2
}
}
KAydedip modelimizide kapatabiliriz artık.Sıra geldi controller olusturmaya . Ben OnlineController olarak adlandırdım. kodlarım ;
<?php
class Backend_OnlineController extends BackendController {
/*
|--------------------------------------------------------------------------
| Default Home Controller
|--------------------------------------------------------------------------
|
| You may wish to use controllers instead of, or in addition to, Closure
| based routes. That's great! Here is an example controller method to
| get you started. To route to this controller, just add the route:
|
| Route::get('/', 'HomeController@showWelcome');
|
*/
public function getOnlinelistele() {
$guests = Online::guests()->get();
$totalGuests = Online::guests()->count();
$registered = Online::registered()->get();
$totalRegistered = Online::registered()->count();
return View::make('backend.online.listele', array('guests' => $guests,
'totalGuests' => $totalGuests,'registered' => $registered,'totalRegistered' => $totalRegistered));
}
KEndi yolunuza göre backend.online.listele kısmını ayarlarsınız ... Benim yolum views/backend/online/listele.blade.php idi.
Ve sonra views imizde online üyeleri listelemeye geldi. listele.blade.php 'imde ki gereken kodlarım ;
<div class="span12 widget">
<div class="widget-header">
<span class="title">Online Üye = {{$totalRegistered}}</span><br>
<span class="title">Online Misafir = {{$totalGuests}} </span>
</div>
<div class="widget-content table-container">
<table class="table table-striped data">
<thead>
<tr>
<th>Ad Soyad</th>
<th>E-Posta Adresi</th>
<th>Slug</th>
</tr>
</thead>
<tbody>
@foreach ($registered as $online)
<tr>
<td>{{$online->user->namesurname}}</td>
<td>{{$online->user->email}}</td>
<td>{{$online->user->namesurnameslug}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>