Skip to content

Commit

Permalink
Allow User model to be set from Config file
Browse files Browse the repository at this point in the history
  • Loading branch information
junaidnasir committed Mar 30, 2016
1 parent 5fc3453 commit 748fe04
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ in `config/larainvite.php` you can set default expiration time in hours from cur
'expires' => 48
```
to change user model, default set to ('App\User') add this in your `AppServiceProvider.php` boot function
you can also change user model to be used, in `larainvite.php`
```php
public function boot()
{
Invite::setUserModel('App\Models\User');
}
'UserModel' => 'App\User'
```
9 changes: 8 additions & 1 deletion src/Config/larainvite.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@
| i.e now() + expires (hours)
|
*/
'expires' => 48
'expires' => 48,

/*
|--------------------------------------------------------------------------
| User Model
|--------------------------------------------------------------------------
*/
'UserModel' => 'App\User'
];
19 changes: 1 addition & 18 deletions src/Models/LaraInviteModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,11 @@ class LaraInviteModel extends Model
*/
protected $table = 'user_invitations';

/**
* User Model (referral)
*
* @var string
*/
protected static $userModel='App\User';

/**
* Referral User
*/
public function user()
{
return $this->belongsTo(static::$userModel);
}

/**
* Set User Model
* call this function in AppServiceProvidor's boot() function
* to overwrite default
*/
public static function setUserModel($model)
{
static::$userModel = $model;
return $this->belongsTo(config('larainvite.UserModel'));
}
}

0 comments on commit 748fe04

Please sign in to comment.