Skip to content

Commit

Permalink
save last login timestamp
Browse files Browse the repository at this point in the history
related to #27
  • Loading branch information
MrKrisKrisu committed May 28, 2020
1 parent 09fd951 commit ed7b489
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Carbon\Carbon;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -46,4 +47,10 @@ public function username()
return 'username';
}

public function authenticated(Request $request, $user)
{
$user->last_login = Carbon::now();
$user->update();
}

}
5 changes: 3 additions & 2 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'username', 'email', 'password'
'username', 'email', 'password', 'last_login'
];

/**
Expand Down Expand Up @@ -60,7 +60,8 @@ public function spotifySessions()
return $this->hasMany(SpotifySession::class);
}

public function reweReceipts() {
public function reweReceipts()
{
return $this->hasMany(ReweBon::class, 'user_id', 'id');
}

Expand Down
35 changes: 35 additions & 0 deletions database/migrations/2020_05_28_165502_add_user_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddUserColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//Last Activity timestamp is important for automatic account deletion
Schema::table('users', function (Blueprint $table) {
$table->timestamp('last_login')
->nullable()
->after('remember_token');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('last_login');
});
}
}

0 comments on commit ed7b489

Please sign in to comment.