Skip to content

Commit

Permalink
add team to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshKisb committed Sep 6, 2024
1 parent dbe5a84 commit de5eb98
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Models;

use App\Traits\IsTenantModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Author extends Model
{
use HasFactory;
use IsTenantModel;

protected $primaryKey = 'author_id';

Expand Down
2 changes: 2 additions & 0 deletions app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Models;

use App\Traits\IsTenantModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
use HasFactory;
use IsTenantModel;

protected $primaryKey = 'id';

Expand Down
2 changes: 2 additions & 0 deletions app/Models/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Services\FileService;
use App\Traits\IsTenantModel;
use App\Traits\SEOable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -11,6 +12,7 @@
class Content extends Model
{
use HasFactory, SEOable;
use IsTenantModel;

protected $primaryKey = 'id';

Expand Down
2 changes: 2 additions & 0 deletions app/Models/ContentCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Models;

use App\Traits\IsTenantModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ContentCategory extends Model
{
use HasFactory;
use IsTenantModel;

protected $primaryKey = 'content_category_id';

Expand Down
2 changes: 2 additions & 0 deletions app/Models/Menu.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
namespace App\Models;

use App\Traits\IsTenantModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Menu extends Model
{
use HasFactory, SoftDeletes;
use IsTenantModel;

protected $fillable = [
'name',
Expand Down
16 changes: 6 additions & 10 deletions app/Models/Page.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?php

/**
* Page Model.
*
* Represents the Page entity in the database with relationships to User, Category, and Tag models.
*/

namespace App\Models;

use App\Traits\IsTenantModel;
use App\Traits\SEOable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Page extends Model
{
use HasFactory, SEOable;
use IsTenantModel;

protected $fillable = [
'title',
Expand All @@ -29,10 +25,10 @@ class Page extends Model
'published_at' => 'datetime',
];

public function category()
{
return $this->belongsTo(Category::class);
}
// public function category()
// {
// return $this->belongsTo(Category::class);
// }

public function user()
{
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Models;

use App\Traits\IsTenantModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
use HasFactory;
use IsTenantModel;

protected $fillable = [
'title',
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Models;

use App\Traits\IsTenantModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Tag extends Model
{
use HasFactory;
use IsTenantModel;

protected $primaryKey = 'id';

Expand Down
15 changes: 15 additions & 0 deletions app/Traits/IsTenantModel.php
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 database/migrations/2024_09_29_093707_add_team_to_resources.php
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');
});
}
}
}
};

0 comments on commit de5eb98

Please sign in to comment.