From fe80559edb0e502a0c1bc87e739a191ad3aadc7a Mon Sep 17 00:00:00 2001 From: Jesus Leon Date: Fri, 18 Mar 2016 22:24:34 +0100 Subject: [PATCH] Patch for Laravel 5.2 --- .../Traits/TeamworkTeamInviteTrait.php | 2 +- .../Teamwork/Traits/TeamworkTeamTrait.php | 6 ++--- src/Mpociot/Teamwork/Traits/UserHasTeams.php | 2 +- src/config/config.php | 22 ++++++++++++++++++- src/database/migrations.stub | 6 ++--- tests/TeamworkTeamInviteTraitTest.php | 2 +- tests/TeamworkTeamTraitTest.php | 4 ++-- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/Mpociot/Teamwork/Traits/TeamworkTeamInviteTrait.php b/src/Mpociot/Teamwork/Traits/TeamworkTeamInviteTrait.php index 7e1d1e0..5fd40a6 100644 --- a/src/Mpociot/Teamwork/Traits/TeamworkTeamInviteTrait.php +++ b/src/Mpociot/Teamwork/Traits/TeamworkTeamInviteTrait.php @@ -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' ); } } diff --git a/src/Mpociot/Teamwork/Traits/TeamworkTeamTrait.php b/src/Mpociot/Teamwork/Traits/TeamworkTeamTrait.php index a68e136..b9f358f 100644 --- a/src/Mpociot/Teamwork/Traits/TeamworkTeamTrait.php +++ b/src/Mpociot/Teamwork/Traits/TeamworkTeamTrait.php @@ -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(); } /** @@ -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"); } /** diff --git a/src/Mpociot/Teamwork/Traits/UserHasTeams.php b/src/Mpociot/Teamwork/Traits/UserHasTeams.php index cadc959..6cdbc74 100644 --- a/src/Mpociot/Teamwork/Traits/UserHasTeams.php +++ b/src/Mpociot/Teamwork/Traits/UserHasTeams.php @@ -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( [ ] ); } diff --git a/src/config/config.php b/src/config/config.php index 4b9a028..9a6e639 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -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 @@ -68,4 +88,4 @@ | */ 'team_invites_table' => 'team_invites', -]; +]; \ No newline at end of file diff --git a/src/database/migrations.stub b/src/database/migrations.stub index 4651bd7..49323c4 100644 --- a/src/database/migrations.stub +++ b/src/database/migrations.stub @@ -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(); } ); @@ -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' ); @@ -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'); }); diff --git a/tests/TeamworkTeamInviteTraitTest.php b/tests/TeamworkTeamInviteTraitTest.php index ca121f7..6c1829b 100644 --- a/tests/TeamworkTeamInviteTraitTest.php +++ b/tests/TeamworkTeamInviteTraitTest.php @@ -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]' ); diff --git a/tests/TeamworkTeamTraitTest.php b/tests/TeamworkTeamTraitTest.php index c650040..e26abef 100644 --- a/tests/TeamworkTeamTraitTest.php +++ b/tests/TeamworkTeamTraitTest.php @@ -31,7 +31,7 @@ public function testGetUsers() { Config::shouldReceive('get') ->once() - ->with('auth.model') + ->with('teamwork.user_model') ->andReturn('User'); Config::shouldReceive('get') @@ -57,7 +57,7 @@ public function testGetOwner() { Config::shouldReceive('get') ->once() - ->with('auth.model') + ->with('teamwork.user_model') ->andReturn('TestUser');