-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
13 changed files
with
251 additions
and
56 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
42 changes: 42 additions & 0 deletions
42
database/migrations/2010_02_13_134649_create_metas_table.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,42 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('metas', function (Blueprint $table) { | ||
$table->id(); | ||
|
||
$table->string('model_id'); | ||
$table->string('model_type'); | ||
|
||
$table->string('connected_id')->nullable(); | ||
$table->string('connected_type')->nullable(); | ||
|
||
$table->string('key')->index(); | ||
$table->json('value')->nullable(); | ||
|
||
$table->timestamps(); | ||
}); | ||
|
||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('metas'); | ||
} | ||
}; |
43 changes: 0 additions & 43 deletions
43
database/migrations/2023_02_13_134649_create_accounts_metas_table.php
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
"label" => "المعلومات", | ||
"single" => "معلومة", | ||
"create" => "إضافة معلومة", | ||
"columns" => [ | ||
"model" => "النموذج", | ||
"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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
"label" => "Metas", | ||
"single" => "Meta", | ||
"create" => "Create Meta", | ||
"columns" => [ | ||
"model" => "Model", | ||
"key" => "Key", | ||
"value" => "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,8 @@ | ||
<span class="fi-ta-text-item-label text-sm leading-6 text-gray-950 dark:text-white"> | ||
@if(is_array($getState())) | ||
{{ json_encode($getState(), JSON_PRETTY_PRINT) }} | ||
@else | ||
{{ $getState() }} | ||
@endif | ||
|
||
</span> |
Empty file.
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,59 @@ | ||
<?php | ||
|
||
namespace TomatoPHP\FilamentMeta\Filament\RelationManager; | ||
|
||
use Filament\Forms\Form; | ||
use Filament\Forms; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
use Filament\Tables\Actions\CreateAction; | ||
use Filament\Tables\Table; | ||
use Filament\Tables; | ||
|
||
class MetaRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'modelMeta'; | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form->schema([ | ||
Forms\Components\TextInput::make('key') | ||
->label(trans('filament-meta::messages.columns.key')) | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('value') | ||
->label(trans('filament-meta::messages.columns.value')) | ||
]); | ||
} | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->headerActions([ | ||
CreateAction::make() | ||
]) | ||
->columns([ | ||
Tables\Columns\TextColumn::make('key') | ||
->label(trans('filament-meta::messages.columns.key')) | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('value') | ||
->label(trans('filament-meta::messages.columns.value')) | ||
->view('filament-meta::table-columns.value') | ||
]) | ||
->headerActions([ | ||
Tables\Actions\CreateAction::make() | ||
]) | ||
->filters([ | ||
|
||
]) | ||
->actions([ | ||
Tables\Actions\ViewAction::make(), | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
} |
Empty file.
Empty file.
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,60 @@ | ||
<?php | ||
|
||
namespace TomatoPHP\FilamentMeta\Models; | ||
|
||
use GeneaLabs\LaravelModelCaching\CachedModel; | ||
use GeneaLabs\LaravelModelCaching\Traits\Cachable; | ||
use Illuminate\Database\Eloquent\Relations\MorphTo; | ||
|
||
/** | ||
* @property integer $id | ||
* @property string $model_id | ||
* @property string $model_type | ||
* @property string $connected_id | ||
* @property string $connected_type | ||
* @property string $key | ||
* @property mixed $value | ||
* @property string $created_at | ||
* @property string $updated_at | ||
*/ | ||
class Meta extends CachedModel | ||
{ | ||
use Cachable; | ||
|
||
protected $cachePrefix = "tomato_meta_"; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'connected_id', | ||
'connected_type', | ||
'model_id', | ||
'model_type', | ||
'key', | ||
'value', | ||
'created_at', | ||
'updated_at' | ||
]; | ||
|
||
protected $casts = [ | ||
'value' => 'array', | ||
]; | ||
|
||
/** | ||
* @return MorphTo | ||
*/ | ||
public function model(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
|
||
/** | ||
* @return MorphTo | ||
*/ | ||
public function connected(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace TomatoPHP\FilamentMeta\Traits; | ||
|
||
use Illuminate\Database\Eloquent\Relations\MorphMany; | ||
|
||
trait HasMeta | ||
{ | ||
/** | ||
* @return MorphMany | ||
*/ | ||
public function modelMeta(): MorphMany | ||
{ | ||
return $this->morphMany('TomatoPHP\FilamentMeta\Models\Meta', 'model'); | ||
} | ||
|
||
|
||
/** | ||
* @param string $key | ||
* @param mixed $value | ||
* @return mixed | ||
*/ | ||
public function meta(string $key, mixed $value=null): mixed | ||
{ | ||
if($value!==null){ | ||
if($value === 'null'){ | ||
return $this->modelMeta()->updateOrCreate(['key' => $key], ['value' => null]); | ||
} | ||
else { | ||
return $this->modelMeta()->updateOrCreate(['key' => $key], ['value' => $value]); | ||
} | ||
} | ||
else { | ||
$meta = $this->modelMeta()->where('key', $key)->first(); | ||
if($meta){ | ||
return $meta->value; | ||
} | ||
else { | ||
return $this->modelMeta()->updateOrCreate(['key' => $key], ['value' => null]); | ||
} | ||
} | ||
} | ||
} |