Skip to content

Commit

Permalink
Merge pull request #35 from lara-zeus/config-model
Browse files Browse the repository at this point in the history
allow to config the models
  • Loading branch information
atmonshi authored Apr 29, 2023
2 parents 2b6ec12 + f0faed0 commit 5903a3f
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 110 deletions.
142 changes: 71 additions & 71 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions config/zeus-wind.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

return [
/**
* set the default path for the blogs homepage.
* set the default path for the contact form homepage.
*/
'path' => 'blog',
'path' => '/',

/**
* the middleware you want to apply on all the blogs routes
* for example if you want to make your blog for users only, add the middleware 'auth'.
*/
'middleware' => ['web'],

/**
* customize the models
*/
'models' => [
'department' => \LaraZeus\Wind\Models\Department::class,
'letter' => \LaraZeus\Wind\Models\Letter::class,
],

/**
* allows you to create multiple departments to receive the messages from your website.
*/
Expand Down
6 changes: 4 additions & 2 deletions database/factories/DepartmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use LaraZeus\Wind\Models\Department;

class DepartmentFactory extends Factory
{
Expand All @@ -12,7 +11,10 @@ class DepartmentFactory extends Factory
*
* @var string
*/
protected $model = Department::class;
public function getModel(): string
{
return config('zeus-wind.models.department');
}

/**
* Define the model's default state.
Expand Down
14 changes: 5 additions & 9 deletions database/factories/LetterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use LaraZeus\Wind\Models\Department;
use LaraZeus\Wind\Models\Letter;

class LetterFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Letter::class;
public function getModel(): string
{
return config('zeus-wind.models.letter');
}

/**
* Define the model's default state.
Expand All @@ -27,7 +23,7 @@ public function definition()
return [
'name' => $this->faker->name,
'email' => $this->faker->email,
'department_id' => Department::factory(),
'department_id' => config('zeus-wind.models.department')::factory(),
'title' => $this->faker->words(3, true),
'message' => $this->faker->words(5, true),
'status' => 'NEW',
Expand Down
20 changes: 10 additions & 10 deletions database/seeders/WindSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

use Illuminate\Database\Seeder;
use LaraZeus\Wind\Models\Department;
use LaraZeus\Wind\Models\Letter;

class WindSeeder extends Seeder
{
public function run()
{
Department::factory()->has(
Letter::factory()
->count(5)
->state(function (array $attributes, Department $department) {
return [
'department_id' => $department->id,
];
})
)->count(3)->create();
config('zeus-wind.models.department')::factory()
->has(
config('zeus-wind.models.letter')::factory()
->count(5)
->state(function (array $attributes, Department $department) {
return [
'department_id' => $department->id,
];
})
)->count(3)->create();
}
}
2 changes: 1 addition & 1 deletion resources/views/themes/zeus/departments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
>
<div x-data="{ state: $wire.entangle('{{ $getStatePath() }}') }">
@if(config('zeus-wind.enableDepartments'))
@php $departments = \LaraZeus\Wind\Models\Department::whereIsActive(1)->orderBy('ordering')->get(); @endphp
@php $departments = config('zeus-wind.models.department')::whereIsActive(1)->orderBy('ordering')->get(); @endphp
@if($departments->isEmpty())
<x-zeus::box shadowless class="max-w-4xl mx-auto">
<div class="text-red-400">
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
use LaraZeus\Wind\Http\Livewire\Contacts;

Route::middleware(config('zeus-wind.middleware'))
->prefix(config('zeus-wind.prefix'))
->prefix(config('zeus-wind.path'))
->get('contact-us/{departmentSlug?}', Contacts::class)
->name('contact');
9 changes: 6 additions & 3 deletions src/Filament/Resources/DepartmentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables\Columns\BooleanColumn;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\Str;
Expand All @@ -19,7 +19,10 @@

class DepartmentResource extends Resource
{
protected static ?string $model = Department::class;
public static function getModel(): string
{
return config('zeus-wind.models.department');
}

protected static ?string $navigationIcon = 'heroicon-o-document-duplicate';

Expand Down Expand Up @@ -77,7 +80,7 @@ public static function table(Table $table): Table
->openUrlInNewTab(),
TextColumn::make('desc')->label(__('desc')),
TextColumn::make('ordering')->sortable()->label(__('ordering')),
BooleanColumn::make('is_active')->sortable()->label(__('is_active')),
IconColumn::make('is_active')->boolean()->sortable()->label(__('is_active')),
ImageColumn::make('logo')->disk(config('zeus-wind.uploads.disk', 'public'))->label(__('logo')),
])
->defaultSort('id', 'desc');
Expand Down
9 changes: 5 additions & 4 deletions src/Filament/Resources/LetterResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ViewColumn;
use LaraZeus\Wind\Filament\Resources\LetterResource\Pages;
use LaraZeus\Wind\Models\Department;
use LaraZeus\Wind\Models\Letter;

class LetterResource extends Resource
{
protected static ?string $model = Letter::class;
public static function getModel(): string
{
return config('zeus-wind.models.letter');
}

protected static ?string $navigationIcon = 'heroicon-o-inbox';

Expand Down Expand Up @@ -44,7 +45,7 @@ public static function form(Form $form): Form
->maxLength(255),
Select::make('department_id')
->label(__('department'))
->options(Department::pluck('name', 'id'))
->options(config('zeus-wind.models.department')::pluck('name', 'id'))
->required()
->visible(fn (): bool => config('zeus-wind.enableDepartments')),
TextInput::make('status')
Expand Down
9 changes: 4 additions & 5 deletions src/Http/Livewire/ContactsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Filament\Forms\Components\ViewField;
use LaraZeus\Wind\Events\LetterSent;
use LaraZeus\Wind\Models\Department;
use LaraZeus\Wind\Models\Letter;
use Livewire\Component;

/**
Expand Down Expand Up @@ -39,9 +38,9 @@ public function mount($departmentSlug)
{
if (config('zeus-wind.enableDepartments')) {
if ($departmentSlug !== null) {
$this->department = Department::where('slug', $departmentSlug)->first();
$this->department = config('zeus-wind.models.department')::where('slug', $departmentSlug)->first();
} else {
$this->department = Department::find(config('zeus-wind.defaultDepartmentId'));
$this->department = config('zeus-wind.models.department')::find(config('zeus-wind.defaultDepartmentId'));
}
}

Expand All @@ -55,7 +54,7 @@ public function mount($departmentSlug)

public function store()
{
$letter = Letter::create($this->form->getState());
$letter = config('zeus-wind.models.letter')::create($this->form->getState());
$this->sent = true;
LetterSent::dispatch($letter);
}
Expand Down Expand Up @@ -93,6 +92,6 @@ protected function getFormSchema(): array
public function render()
{
return view(app('wind-theme') . '.contact-form')
->with('departments', Department::where('is_active', 1)->orderBy('ordering')->get());
->with('departments', config('zeus-wind.models.department')::where('is_active', 1)->orderBy('ordering')->get());
}
}
2 changes: 1 addition & 1 deletion src/Models/Department.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ protected static function newFactory()

public function letters()
{
return $this->hasMany(Letter::class);
return $this->hasMany(config('zeus-wind.models.letter'));
}
}
2 changes: 1 addition & 1 deletion src/Models/Letter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected static function newFactory()

public function department()
{
return $this->belongsTo(Department::class);
return $this->belongsTo(config('zeus-wind.models.department'));
}

public function getReplyTitleAttribute($value)
Expand Down

0 comments on commit 5903a3f

Please sign in to comment.