Skip to content
This repository was archived by the owner on Jun 1, 2019. It is now read-only.

Commit 821e703

Browse files
committed
add laravel 5.2 compatibility
1 parent 7046327 commit 821e703

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All Notable changes to `activitylog` will be documented in this file
44

5+
### 2.3.0
6+
- Add compatibility with Laravel 5.2
7+
58
### 2.2.1
69
- Use database_path
710

src/Spatie/Activitylog/Models/Activity.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Eloquent;
66
use Config;
7+
use Exception;
78

89
class Activity extends Eloquent
910
{
@@ -21,7 +22,22 @@ class Activity extends Eloquent
2122
*/
2223
public function user()
2324
{
24-
return $this->belongsTo(Config::get('auth.model'), 'user_id');
25+
return $this->belongsTo($this->getAuthModelName(), 'user_id');
26+
}
27+
28+
public function getAuthModelName()
29+
{
30+
//laravel 5.0 - 5.1
31+
if (! is_null(config('auth.model'))) {
32+
return config('auth.model');
33+
}
34+
35+
//laravel 5.2
36+
if (! is_null(config('auth.providers.users.model'))) {
37+
return config('auth.providers.users.model');
38+
}
39+
40+
throw new Exception('could not determine the model name for users');
2541
}
2642

2743
protected $guarded = ['id'];

0 commit comments

Comments
 (0)