Skip to content

Commit

Permalink
Added Laravel 8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
oliuz committed Sep 14, 2020
1 parent fdce53c commit ae58c8e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 40 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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');
});
}

Expand All @@ -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');
});
}
Expand Down
18 changes: 18 additions & 0 deletions routes/routes.php
Original file line number Diff line number Diff line change
@@ -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');
});
22 changes: 0 additions & 22 deletions routes/routes.stub

This file was deleted.

2 changes: 1 addition & 1 deletion src/Commands/MakeTeamwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
7 changes: 4 additions & 3 deletions src/TeamworkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mpociot\Teamwork;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;

/**
Expand Down Expand Up @@ -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');
}
}
Expand All @@ -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');
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Traits/UserHasTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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')) {
Expand Down
4 changes: 2 additions & 2 deletions stubs/models/Team.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace {{namespace}}Models;
namespace App\Models;

use Mpociot\Teamwork\Models\TeamworkTeam;

class Team extends TeamworkTeam
{

}

0 comments on commit ae58c8e

Please sign in to comment.