Skip to content

Commit a5f9282

Browse files
author
Sebastian Fix
committed
wip
1 parent 7529490 commit a5f9282

18 files changed

Lines changed: 244 additions & 15 deletions

app/Actions/ViewDataAction.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\DTO\ContactDTO;
66
use App\Enums\ContactSectionEnum;
7+
use App\Models\Configuration;
78
use App\Models\Contact;
89
use App\Models\News;
910
use App\Models\Product;
@@ -14,6 +15,15 @@
1415

1516
class ViewDataAction
1617
{
18+
public function configuration(string $locale): Configuration
19+
{
20+
$key = Str::slug("configuration_{$locale}");
21+
22+
return Cache::rememberForever($key, function () {
23+
return Configuration::first();
24+
});
25+
}
26+
1727
public function products(string $locale): Collection
1828
{
1929
$key = Str::slug("products_published_{$locale}");

app/Models/Configuration.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Spatie\Translatable\HasTranslations;
8+
9+
class Configuration extends Model
10+
{
11+
use HasFactory;
12+
use HasTranslations;
13+
14+
public array $translatable = ['footer'];
15+
16+
protected $casts = [
17+
'footer' => 'json',
18+
];
19+
}

app/View/Components/AppLayout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function render(): View
1717
$locale = app()->getLocale();
1818

1919
return view('layouts.app')->with([
20+
'configuration' => (new ViewDataAction)->configuration($locale),
2021
'locales' => LocaleEnum::cases(),
2122
'locale' => Str::slug($locale),
2223
'page' => $this->page,

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"spatie/laravel-permission": "^6.7",
2424
"spatie/laravel-responsecache": "^7.6",
2525
"spatie/laravel-sitemap": "^7.3",
26+
"spatie/laravel-translatable": "^6.11",
2627
"spatie/security-advisories-health-check": "^1.2"
2728
},
2829
"require-dev": {

composer.lock

Lines changed: 84 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
/**
8+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Configuration>
9+
*/
10+
class ConfigurationFactory extends Factory
11+
{
12+
/**
13+
* Define the model's default state.
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public function definition(): array
18+
{
19+
return [
20+
//
21+
];
22+
}
23+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('configurations', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('logo')->nullable();
17+
$table->json('contact')->nullable();
18+
$table->json('terms')->nullable();
19+
$table->json('imprint')->nullable();
20+
$table->json('privacy')->nullable();
21+
$table->json('footer')->nullable();
22+
$table->timestamps();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('configurations');
32+
}
33+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Database\Seeders\Paperflakes;
4+
5+
use App\Enums\LocaleEnum;
6+
use App\Models\Configuration;
7+
use Illuminate\Database\Seeder;
8+
9+
class ConfigurationsTableSeeder extends Seeder
10+
{
11+
/**
12+
* Run the database seeds.
13+
*/
14+
public function run(): void
15+
{
16+
Configuration::updateOrCreate([], [
17+
'logo' => 'layouts._logos._paperflakes',
18+
'footer' => [
19+
LocaleEnum::DE->value => 'paperflakes AG',
20+
],
21+
]);
22+
}
23+
}

database/seeders/PaperflakesSeeder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Database\Seeders;
44

5+
use Database\Seeders\Paperflakes\ConfigurationsTableSeeder;
56
use Database\Seeders\Paperflakes\ContactsTableSeeder;
67
use Database\Seeders\Paperflakes\NewsTableSeeder;
78
use Database\Seeders\Paperflakes\PagesTableSeeder;
@@ -18,6 +19,7 @@ class PaperflakesSeeder extends Seeder
1819
*/
1920
public function run(): void
2021
{
22+
$this->call(ConfigurationsTableSeeder::class);
2123
$this->call(PagesTableSeeder::class);
2224
$this->call(NewsTableSeeder::class);
2325
$this->call(ProductsTableSeeder::class);

lang/de_CH.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"EN": "EN",
1818
"English": "English",
1919
"Google Maps": "Google Maps",
20+
"Headquarter": "Hauptsitz",
2021
"Imprint": "Impressum",
2122
"Info(at)paperflakes.ch": "Info(at)paperflakes.ch",
2223
"Jobs": "Jobs",

0 commit comments

Comments
 (0)