generated from vormkracht10/filament-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d7844ff
commit 984f737
Showing
11 changed files
with
210 additions
and
47 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
database/migrations/add_columns_to_redirects_table_for_backstage.php.stub
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 | ||
|
||
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::table('redirects', function (Blueprint $table) { | ||
$table->after('ulid', function ($table) { | ||
$table->foreignUlid('site_ulid')->nullable()->constrained(table: 'sites', column: 'ulid')->cascadeOnUpdate()->cascadeOnDelete(); | ||
$table->char('language_code', 2)->nullable(); | ||
$table->char('country_code', 2)->nullable(); | ||
$table->foreignUlid('content_ulid')->nullable()->constrained(table: 'content', column: 'ulid')->cascadeOnUpdate()->cascadeOnDelete(); | ||
}); | ||
|
||
$table->foreign(['language_code', 'country_code'])->references(['code', 'country_code'])->on('languages')->cascadeOnUpdate()->nullOnDelete(); | ||
}); | ||
} | ||
}; |
23 changes: 0 additions & 23 deletions
23
database/migrations/create_redirects_table_filament.php.stub
This file was deleted.
Oops, something went wrong.
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
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,75 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\FilamentRedirects\Imports; | ||
|
||
use Vormkracht10\Redirects\Models\Redirect; | ||
use Filament\Actions\Imports\ImportColumn; | ||
use Filament\Actions\Imports\Importer; | ||
use Filament\Actions\Imports\Models\Import; | ||
|
||
class RedirectImporter extends Importer | ||
{ | ||
protected static ?string $model = Redirect::class; | ||
|
||
public static function getColumns(): array | ||
{ | ||
return [ | ||
ImportColumn::make('site_ulid') | ||
->label(__('Site')) | ||
->requiredMapping() | ||
->guess(['site', 'site_ulid']), | ||
ImportColumn::make('language_code') | ||
->label(__('Language Code')) | ||
->requiredMapping() | ||
->guess(['language', 'language_code']), | ||
ImportColumn::make('country_code') | ||
->label(__('Country Code')) | ||
->guess(['KvKnr']), | ||
ImportColumn::make('content_ulid') | ||
->label(__('Content')) | ||
->requiredMapping() | ||
->guess(['content', 'content_ulid']), | ||
ImportColumn::make('source') | ||
->requiredMapping() | ||
->label(__('Source')) | ||
->guess(['source']), | ||
ImportColumn::make('destination') | ||
->requiredMapping() | ||
->label(__('Destination')) | ||
->guess(['destination']), | ||
ImportColumn::make('code') | ||
->requiredMapping() | ||
->rules(['max:3']) | ||
->guess(['code', 'status', 'status_code']), | ||
ImportColumn::make('hits') | ||
->requiredMapping() | ||
->guess(['hits']), | ||
]; | ||
} | ||
|
||
public function resolveRecord(): ?Redirect | ||
{ | ||
if (isset($this->data['source'])) { | ||
return Redirect::firstOrNew([ | ||
'source' => $this->data['source'], | ||
]); | ||
} | ||
} | ||
|
||
public static function getCompletedNotificationBody(Import $import): string | ||
{ | ||
$body = __('Your redirects import has completed and :numbers :row imported.', [ | ||
'numbers' => number_format($import->successful_rows), | ||
'row' => str('row')->plural($import->successful_rows), | ||
]); | ||
|
||
if ($failedRowsCount = $import->getFailedRowsCount()) { | ||
$body .= __(' :numbers :row failed to import.', [ | ||
'numbers' => number_format($failedRowsCount), | ||
'row' => str('row')->plural($failedRowsCount), | ||
]); | ||
} | ||
|
||
return $body; | ||
} | ||
} |
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 | ||
|
||
namespace Vormkracht10\FilamentRedirects\Middleware; | ||
|
||
class MatchRedirects {} |
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