-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from PortableStudios/feature/FILACMS-10_Add_tax…
…onomy_relationships Feature/filacms 10 add taxonomy relationships
- Loading branch information
Showing
45 changed files
with
1,000 additions
and
96 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
26 changes: 26 additions & 0 deletions
26
database/migrations/2024_02_23_000000_create_taxonomy_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,26 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('taxonomy_resources', function (Blueprint $table) { | ||
$table->string('resource_class'); | ||
$table->foreignId('taxonomy_id')->constrained()->cascadeOnDelete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('taxonomy_resources'); | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
database/migrations/2024_02_23_222545_create_taxonomyables.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,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('taxonomyables', function (Blueprint $table) { | ||
$table->foreignId('taxonomy_term_id')->references('id')->on('taxonomy_terms')->cascadeOnDelete(); | ||
$table->foreignId('taxonomyable_id'); | ||
$table->string('taxonomyable_type'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('taxonomyables'); | ||
} | ||
}; |
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,71 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
.main-content { | ||
@apply md:pl-12 md:pr-12; | ||
} | ||
|
||
.page-header { | ||
@apply bg-gray-200 md:pl-12 md:pr-12 pt-4 pb-4 mb-4; | ||
} | ||
|
||
.logo-wrapper { | ||
@apply border bg-white p-4 pt-2 pb-2 inline-block rounded-lg; | ||
} | ||
|
||
.page-footer { | ||
@apply bg-gray-200 md:pl-12 md:pr-12 pt-4 pb-4 mt-4 text-center; | ||
} | ||
|
||
h1 { | ||
@apply text-3xl font-bold mb-4 pb-2 border-b; | ||
} | ||
|
||
.filters-column { | ||
@apply w-1/5; | ||
} | ||
|
||
.listing-column { | ||
@apply w-4/5 pl-6 w-full; | ||
} | ||
|
||
.btn-primary { | ||
@apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded; | ||
} | ||
|
||
.authors { | ||
@apply italic mb-2; | ||
} | ||
|
||
.taxonomies { | ||
@apply text-sm pt-4; | ||
} | ||
|
||
.taxonomy-term { | ||
@apply inline-block rounded bg-gray-100 p-1; | ||
} | ||
|
||
.content-listing-card { | ||
@apply md:w-1/5 w-full border rounded-lg inline-block; | ||
} | ||
|
||
.content-listing-card__image { | ||
@apply w-full h-32 rounded-t-lg overflow-hidden; | ||
} | ||
|
||
.content-listing-card__content { | ||
@apply p-4; | ||
} | ||
|
||
.content-listing-card__title { | ||
@apply text-lg font-bold mb-2; | ||
} | ||
|
||
.content-listing-card__excerpt { | ||
@apply text-sm; | ||
} | ||
|
||
.content-listing-card a { | ||
@apply italic; | ||
} |
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,5 @@ | ||
<?php | ||
|
||
use Portable\FilaCms\Facades\FilaCms; | ||
|
||
FilaCms::contentRoutes(); |
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,25 @@ | ||
<?php | ||
|
||
namespace Portable\FilaCms\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class DynamicTermIds implements CastsAttributes | ||
{ | ||
protected $taxonomyId; | ||
|
||
public function __construct($taxonomyId) | ||
{ | ||
$this->taxonomyId = $taxonomyId; | ||
} | ||
|
||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return $model->terms()->where('taxonomy_id', $this->taxonomyId)->pluck('id'); | ||
} | ||
|
||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return [$key => $value]; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Portable\FilaCms\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class DynamicTermList implements CastsAttributes | ||
{ | ||
protected $taxonomyId; | ||
|
||
public function __construct($taxonomyId) | ||
{ | ||
$this->taxonomyId = $taxonomyId; | ||
} | ||
|
||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return $model->terms()->where('taxonomy_id', $this->taxonomyId)->get(); | ||
} | ||
|
||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return [$key => $value]; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Portable\FilaCms\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class FilaCms extends Facade | ||
{ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'fila-cms'; | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace Portable\FilaCms; | ||
|
||
use Filament\Facades\Filament; | ||
use Illuminate\Support\Facades\Route; | ||
use Portable\FilaCms\Filament\Resources\AbstractContentResource; | ||
use Portable\FilaCms\Livewire\ContentResourceList; | ||
use Portable\FilaCms\Livewire\ContentResourceShow; | ||
use ReflectionClass; | ||
|
||
class FilaCms | ||
{ | ||
protected static $contentResources = null; | ||
|
||
protected static $contentModels = null; | ||
|
||
public function getContentModelResource($modelClass) | ||
{ | ||
if (is_null(self::$contentModels)) { | ||
$this->getContentModels(); | ||
} | ||
|
||
return isset(self::$contentModels[$modelClass]) ? self::$contentModels[$modelClass] : null; | ||
} | ||
|
||
public function getContentModels() | ||
{ | ||
if (! is_null(self::$contentResources) && ! is_null(self::$contentModels)) { | ||
return self::$contentResources; | ||
} | ||
|
||
$options = []; | ||
static::$contentModels = []; | ||
foreach (Filament::getPanels() as $panel) { | ||
foreach ($panel->getResources() as $resourceClass) { | ||
$reflectionObject = new ReflectionClass($resourceClass); | ||
if ($reflectionObject->isSubclassOf(AbstractContentResource::class)) { | ||
$options[$resourceClass] = $resourceClass::getNavigationLabel(); | ||
static::$contentModels[$resourceClass::getModel()] = $resourceClass; | ||
} | ||
} | ||
} | ||
static::$contentResources = $options; | ||
|
||
return $options; | ||
} | ||
|
||
public function contentRoutes() | ||
{ | ||
$this->getContentModels(); | ||
foreach (static::$contentModels as $modelClass => $resourceClass) { | ||
$prefix = method_exists($resourceClass, 'getFrontendRoutePrefix') ? $resourceClass::getFrontendRoutePrefix() : $resourceClass::getRoutePrefix(); | ||
$registerIndex = method_exists($resourceClass, 'registerIndexRoute') ? $resourceClass::registerIndexRoute() : true; | ||
$registerShow = method_exists($resourceClass, 'registerShowRoute') ? $resourceClass::registerShowRoute() : true; | ||
$feIndexComponent = method_exists($resourceClass, 'getFrontendIndexComponent') ? $resourceClass::getFrontendIndexComponent() : ContentResourceList::class; | ||
$feShowComponent = method_exists($resourceClass, 'getFrontendShowComponent') ? $resourceClass::getFrontendShowComponent() : ContentResourceShow::class; | ||
|
||
Route::group( | ||
['prefix' => $prefix, 'middleware' => 'web'], | ||
function () use ($feShowComponent, $prefix, $registerIndex, $registerShow, $feIndexComponent, $modelClass) { | ||
if ($registerIndex) { | ||
Route::get('/', $feIndexComponent) | ||
->name($prefix.'.index') | ||
->defaults('model', $modelClass); | ||
} | ||
if ($registerShow) { | ||
Route::get('/{slug}', $feShowComponent)->name($prefix.'.show')->defaults('model', $modelClass); | ||
} | ||
} | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.