From ae58c8eaae1512c83e8d8828f576aea04f9237d9 Mon Sep 17 00:00:00 2001 From: oliuz Date: Mon, 14 Sep 2020 16:11:51 -0400 Subject: [PATCH] Added Laravel 8 support --- composer.json | 4 ++-- ...0001_teamwork_add_uuid_in_teams_table.php} | 8 +++---- routes/routes.php | 18 +++++++++++++++ routes/routes.stub | 22 ------------------- src/Commands/MakeTeamwork.php | 2 +- src/TeamworkServiceProvider.php | 7 +++--- src/Traits/UserHasTeams.php | 12 +++++----- stubs/models/Team.stub | 4 ++-- 8 files changed, 37 insertions(+), 40 deletions(-) rename database/migrations/{2020_06_10_182545_add_uuid_in_teams_table.php => 2016_05_18_000001_teamwork_add_uuid_in_teams_table.php} (60%) create mode 100755 routes/routes.php delete mode 100755 routes/routes.stub diff --git a/composer.json b/composer.json index 24bfaa1..88e46c8 100755 --- a/composer.json +++ b/composer.json @@ -18,12 +18,12 @@ "prefer-stable" : true, "require": { "php": "^7.2", - "laravel/framework": "^6.0|^7.0" + "laravel/framework": "^6.0|^7.0|^8.0" }, "require-dev": { "phpunit/phpunit": "^8.0|^9.0", "mockery/mockery": "^1.0", - "illuminate/database": "^6.0|^7.0", + "illuminate/database": "^6.0|^7.0|^8.0", "orchestra/testbench": "^4.0|^5.0" }, "autoload": { diff --git a/database/migrations/2020_06_10_182545_add_uuid_in_teams_table.php b/database/migrations/2016_05_18_000001_teamwork_add_uuid_in_teams_table.php similarity index 60% rename from database/migrations/2020_06_10_182545_add_uuid_in_teams_table.php rename to database/migrations/2016_05_18_000001_teamwork_add_uuid_in_teams_table.php index 010a204..000e477 100644 --- a/database/migrations/2020_06_10_182545_add_uuid_in_teams_table.php +++ b/database/migrations/2016_05_18_000001_teamwork_add_uuid_in_teams_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class AddUuidInTeamsTable extends Migration +class TeamworkAddUuidInTeamsTable extends Migration { /** * Run the migrations. @@ -13,8 +13,8 @@ class AddUuidInTeamsTable extends Migration */ public function up() { - Schema::table(config('teamwork.team_user_table'), function (Blueprint $table) { - $table->uuid('uuid')->nullable(); + Schema::table(config('teamwork.teams_table'), function (Blueprint $table) { + $table->uuid('uuid')->nullable()->after('id'); }); } @@ -25,7 +25,7 @@ public function up() */ public function down() { - Schema::table(config('teamwork.team_user_table'), function (Blueprint $table) { + Schema::table(config('teamwork.teams_table'), function (Blueprint $table) { $table->dropColumn('uuid'); }); } diff --git a/routes/routes.php b/routes/routes.php new file mode 100755 index 0000000..4609fa1 --- /dev/null +++ b/routes/routes.php @@ -0,0 +1,18 @@ +/** + * Teamwork routes + */ +Route::resource('teams', App\Http\Controllers\Teamwork\TeamController::class) +->except('create'); + +Route::prefix('teams')->group(function () { + Route::get('teams/switch/{team}', App\Http\Controllers\Teamwork\TeamSwitchController::class)->name('teams.switch'); + + Route::get('members/{team}', [App\Http\Controllers\Teamwork\TeamMemberController::class, 'show'])->name('teams.members.show'); + Route::delete('members/{team}/{user}', [App\Http\Controllers\Teamwork\TeamMemberController::class, 'destroy'])->name('teams.members.destroy'); + + Route::post('members/{team}', [App\Http\Controllers\Teamwork\TeamInviteController::class, 'store'])->name('teams.members.invite'); + Route::get('members/resend/{invite}', [App\Http\Controllers\Teamwork\TeamInviteController::class, 'update'])->name('teams.members.resend_invite'); + Route::delete('members/{invite}', [App\Http\Controllers\Teamwork\TeamInviteController::class, 'destroy'])->name('teams.members.invite_destroy'); + + Route::get('accept/{token}', App\Http\Controllers\Teamwork\AuthController::class)->name('teams.accept_invite'); +}); diff --git a/routes/routes.stub b/routes/routes.stub deleted file mode 100755 index 26b8453..0000000 --- a/routes/routes.stub +++ /dev/null @@ -1,22 +0,0 @@ - -/** - * Teamwork routes - */ -Route::group(['prefix' => 'teams', 'namespace' => 'Teamwork'], function() -{ - Route::get('/', 'TeamController@index')->name('teams.index'); - //Route::get('create', 'TeamController@create')->name('teams.create'); - Route::post('teams', 'TeamController@store')->name('teams.store'); - Route::get('edit/{team}', 'TeamController@edit')->name('teams.edit'); - Route::put('edit/{team}', 'TeamController@update')->name('teams.update'); - Route::delete('destroy/{team}', 'TeamController@destroy')->name('teams.destroy'); - Route::get('switch/{team}', 'TeamSwitchController')->name('teams.switch'); - - Route::get('members/{team}', 'TeamMemberController@show')->name('teams.members.show'); - Route::post('members/{team}', 'TeamInviteController@store')->name('teams.members.invite'); - Route::get('members/resend/{invite}', 'TeamInviteController@update')->name('teams.members.resend_invite'); - Route::delete('members/{invite}', 'TeamInviteController@destroy')->name('teams.members.invite_destroy'); - Route::delete('members/{team}/{user}', 'TeamMemberController@destroy')->name('teams.members.destroy'); - - Route::get('accept/{token}', 'AuthController')->name('teams.accept_invite'); -}); diff --git a/src/Commands/MakeTeamwork.php b/src/Commands/MakeTeamwork.php index 408a7f8..ea8419e 100755 --- a/src/Commands/MakeTeamwork.php +++ b/src/Commands/MakeTeamwork.php @@ -141,7 +141,7 @@ public function handle() file_put_contents( // app_path('Http/routes.php'), base_path('routes/web.php'), - file_get_contents(__DIR__.'/../../routes/routes.stub'), + file_get_contents(__DIR__.'/../../routes/routes.php'), FILE_APPEND ); diff --git a/src/TeamworkServiceProvider.php b/src/TeamworkServiceProvider.php index d0405d2..b2d0efb 100755 --- a/src/TeamworkServiceProvider.php +++ b/src/TeamworkServiceProvider.php @@ -2,6 +2,7 @@ namespace Mpociot\Teamwork; +use Illuminate\Support\Facades\DB; use Illuminate\Support\ServiceProvider; /** @@ -56,7 +57,7 @@ protected function publishMigrationTeamwork() // Publish the migration $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__ . '../database/migrations/2016_05_18_000000_teamwork_setup_tables.php' => database_path('migrations/' . $timestamp . '_teamwork_setup_tables.php'), + __DIR__ . '/../database/migrations/2016_05_18_000000_teamwork_setup_tables.php' => database_path('migrations/' . $timestamp . '_teamwork_setup_tables.php'), ], 'teamwork-migrations'); } } @@ -68,9 +69,9 @@ protected function publishMigrationUuid() { if (!class_exists('AddUuidInTeamsTable')) { // Publish the migration - $timestamp = date('Y_m_d_His', time()); + $timestamp = DB::raw(now()->addMinutes(3)->format('Y_m_d_His')); $this->publishes([ - __DIR__ . '../database/migrations/2020_06_10_182545_add_uuid_in_teams_table.php' => database_path('migrations/' . $timestamp . '_add_uuid_in_teams_table.php'), + __DIR__ . '/../database/migrations/2016_05_18_000001_teamwork_add_uuid_in_teams_table.php' => database_path('migrations/' . $timestamp . '_teamwork_add_uuid_in_teams_table.php'), ], 'teamwork-add_uuid_migration'); } } diff --git a/src/Traits/UserHasTeams.php b/src/Traits/UserHasTeams.php index 67c0bf9..1d41b80 100755 --- a/src/Traits/UserHasTeams.php +++ b/src/Traits/UserHasTeams.php @@ -39,7 +39,7 @@ public function teams() */ public function currentTeam() { - return $this->hasOne(Config::get('teamwork.team_model'), 'id', 'current_team_id'); + return $this->hasOne(Config::get('teamwork.team_model'), 'id', 'current_team'); } /** @@ -143,8 +143,8 @@ public function attachTeam($team, $pivotData = []) * If the user has no current team, * use the attached one */ - if (is_null($this->current_team_id)) { - $this->current_team_id = $team; + if (is_null($this->current_team)) { + $this->current_team = $team; $this->save(); if ($this->relationLoaded('currentTeam')) { @@ -189,8 +189,8 @@ public function detachTeam($team) * If the user has no more teams, * unset the current_team_id */ - if ($this->teams()->count() === 0 || $this->current_team_id === $team) { - $this->current_team_id = null; + if ($this->teams()->count() === 0 || $this->current_team === $team) { + $this->current_team = null; $this->save(); if ($this->relationLoaded('currentTeam')) { @@ -254,7 +254,7 @@ public function switchTeam($team) throw $exception; } } - $this->current_team_id = $team; + $this->current_team = $team; $this->save(); if ($this->relationLoaded('currentTeam')) { diff --git a/stubs/models/Team.stub b/stubs/models/Team.stub index 48b7abc..f61fec0 100644 --- a/stubs/models/Team.stub +++ b/stubs/models/Team.stub @@ -1,10 +1,10 @@