Support the ongoing development of Laravel.io →
Authentication Session Eloquent
Last updated 2 years ago.
0

Thank you for sharing this, I can use it in my current project that I am rewriting from django.

Last updated 2 years ago.
0

Oh wow, thank you for this. Very useful!

Last updated 2 years ago.
0

Thank you.

Last updated 2 years ago.
0

Thanks a lot Bruno, maybe you want to update your laravel starter kit to use sentry 3, or maybe add more awesomeness :D

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

works great :D

Last updated 2 years ago.
0

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
    }

}
Last updated 2 years ago.
0

I'm wondering how a new session is CREATED or DESTROYED. All I'm seeing is UPDATING an existing.

0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.