Skip to content

Commit

Permalink
Merge pull request #25 from JesusContributions/patch-l52
Browse files Browse the repository at this point in the history
Patch for Laravel 5.2
  • Loading branch information
mpociot committed Mar 18, 2016
2 parents 03cc325 + fe80559 commit b335b7d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Mpociot/Teamwork/Traits/TeamworkTeamInviteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function team()
*/
public function user()
{
return $this->hasOne( Config::get( 'auth.model' ), 'email', 'email' );
return $this->hasOne( Config::get( 'teamwork.user_model' ), 'email', 'email' );
}

}
6 changes: 3 additions & 3 deletions src/Mpociot/Teamwork/Traits/TeamworkTeamTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function invites()
*/
public function users()
{
return $this->belongsToMany(Config::get('auth.model'), Config::get('teamwork.team_user_table'), 'team_id','user_id')->withTimestamps();
return $this->belongsToMany(Config::get('teamwork.user_model'), Config::get('teamwork.team_user_table'), 'team_id','user_id')->withTimestamps();
}

/**
Expand All @@ -40,9 +40,9 @@ public function users()
*/
public function owner()
{
$userModel = Config::get( 'auth.model' );
$userModel = Config::get( 'teamwork.user_model' );
$userKeyName = ( new $userModel() )->getKeyName();
return $this->hasOne(Config::get('auth.model'), $userKeyName, "owner_id");
return $this->hasOne(Config::get('teamwork.user_model'), $userKeyName, "owner_id");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Mpociot/Teamwork/Traits/UserHasTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function bootUserHasTeams()
{
static::deleting( function ( Model $user )
{
if ( !method_exists( Config::get( 'auth.model' ), 'bootSoftDeletes' ) )
if ( !method_exists( Config::get( 'teamwork.user_model' ), 'bootSoftDeletes' ) )
{
$user->teams()->sync( [ ] );
}
Expand Down
22 changes: 21 additions & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@
*/

return [
/*
|--------------------------------------------------------------------------
| Auth Model
|--------------------------------------------------------------------------
|
| This is the Auth model used by Teamwork.
|
*/
'user_model' => App\User::class,

/*
|--------------------------------------------------------------------------
| Teamwork users Table
|--------------------------------------------------------------------------
|
| This is the users table name used by Teamwork.
|
*/
'users_table' => 'users',

/*
|--------------------------------------------------------------------------
| Teamwork Team Model
Expand Down Expand Up @@ -68,4 +88,4 @@
|
*/
'team_invites_table' => 'team_invites',
];
];
6 changes: 3 additions & 3 deletions src/database/migrations.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TeamworkSetupTables extends Migration
*/
public function up()
{
Schema::table( 'users', function ( Blueprint $table )
Schema::table( \Config::get( 'teamwork.users_table' ), function ( Blueprint $table )
{
$table->integer( 'current_team_id' )->unsigned()->nullable();
} );
Expand Down Expand Up @@ -46,7 +46,7 @@ class TeamworkSetupTables extends Migration

$table->foreign( 'user_id' )
->references( \Config::get( 'teamwork.user_foreign_key' ) )
->on( 'users' )
->on( \Config::get( 'teamwork.users_table' ) )
->onUpdate( 'cascade' )
->onDelete( 'cascade' );

Expand All @@ -61,7 +61,7 @@ class TeamworkSetupTables extends Migration
*/
public function down()
{
Schema::table('users', function(Blueprint $table)
Schema::table(\Config::get( 'teamwork.users_table' ), function(Blueprint $table)
{
$table->dropColumn('current_team_id');
});
Expand Down
2 changes: 1 addition & 1 deletion tests/TeamworkTeamInviteTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testGetUser()
{
Config::shouldReceive('get')
->once()
->with('auth.model')
->with('teamwork.user_model')
->andReturn('User');

$stub = m::mock( 'TestUserTeamInviteTraitStub[hasOne]' );
Expand Down
4 changes: 2 additions & 2 deletions tests/TeamworkTeamTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testGetUsers()
{
Config::shouldReceive('get')
->once()
->with('auth.model')
->with('teamwork.user_model')
->andReturn('User');

Config::shouldReceive('get')
Expand All @@ -57,7 +57,7 @@ public function testGetOwner()
{
Config::shouldReceive('get')
->once()
->with('auth.model')
->with('teamwork.user_model')
->andReturn('TestUser');


Expand Down

0 comments on commit b335b7d

Please sign in to comment.