-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Traits; | ||
|
||
use App\Models\Team; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
trait IsTenantModel | ||
{ | ||
|
||
public function team(): BelongsTo | ||
{ | ||
return $this->belongsTo(Team::class); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
database/migrations/2024_09_29_093707_add_team_to_resources.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
|
||
protected $tables = [ | ||
'pages', 'menus', 'content_categories', 'comments', 'posts', 'contents', | ||
'home_contents', 'contacts', 'authors', 'tags' | ||
|
||
]; | ||
|
||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
foreach ($this->tables as $table) { | ||
if (!Schema::hasColumn($table, 'team_id')) { | ||
Schema::table($table, function (Blueprint $table) { | ||
$table->foreignId('team_id')->nullable()->constrained()->onDelete('cascade')->default(1); | ||
}); | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
foreach ($this->tables as $table) { | ||
if (Schema::hasColumn($table, 'team_id')) { | ||
Schema::table($table, function (Blueprint $table) { | ||
$table->dropForeign(['team_id']); | ||
$table->dropColumn('team_id'); | ||
}); | ||
} | ||
} | ||
} | ||
}; |