Thank you for sharing this, I can use it in my current project that I am rewriting from django.
Oh wow, thank you for this. Very useful!
Thanks a lot Bruno, maybe you want to update your laravel starter kit to use sentry 3, or maybe add more awesomeness :D
ghprod said:
Thanks a lot Bruno, maybe you want to update your laravel starter kit to use sentry 3, or maybe add more awesomeness :D
It's on the works.
No need for Sentry! Changet it to normal Laravel 4 style.
Replace Online.php
<?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' => !empty(Auth::user()) ? 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
}
}
I'm wondering how a new session is CREATED or DESTROYED. All I'm seeing is UPDATING an existing.
RichardKeep said:
I'm wondering how a new session is CREATED or DESTROYED. All I'm seeing is UPDATING an existing.
Exactly, I don't see a way where it removes no longer online users.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community