Added blog, pages, menu, category
This commit is contained in:
150
app/Filament/Resources/BlogResource.php
Normal file
150
app/Filament/Resources/BlogResource.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\BlogResource\Pages;
|
||||
use App\Filament\Resources\BlogResource\RelationManagers;
|
||||
use App\Models\Blog;
|
||||
use App\Models\Category;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BlogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Blog::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-m-newspaper';
|
||||
|
||||
protected static ?string $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
$categories = Category::pluck('name', 'id')->toArray();
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('Post Information')
|
||||
->description('Add a new post')
|
||||
->schema([
|
||||
TextInput::make('post')->label('Post Title')
|
||||
->required()
|
||||
->live(1)
|
||||
->columnSpanFull()
|
||||
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
||||
|
||||
TextInput::make('slug')
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
|
||||
Select::make('category_id')
|
||||
->relationship('category', 'name')
|
||||
->label('Category')
|
||||
->searchable()
|
||||
->required()
|
||||
->preload(10)
|
||||
->columnSpan(1),
|
||||
|
||||
Select::make('is_published')
|
||||
->options([
|
||||
0 => 'Draft',
|
||||
1 => 'Published'
|
||||
])
|
||||
->searchable()
|
||||
->default(1)
|
||||
->required()
|
||||
->label('Status')
|
||||
->columnSpan(1),
|
||||
|
||||
RichEditor::make('content')
|
||||
->label('Page Content')
|
||||
->columnSpan(4),
|
||||
|
||||
FileUpload::make('post_image')
|
||||
->label('Custom Image (Optional)')
|
||||
->directory('media/posts')
|
||||
->columnSpan(4)
|
||||
->preserveFilenames()
|
||||
->image()
|
||||
->maxSize(2048),
|
||||
])
|
||||
->columns(4),
|
||||
|
||||
Section::make('Customize Post')
|
||||
->description('Modifiy Post SEO and Meta Information')
|
||||
->schema([
|
||||
KeyValue::make('meta')
|
||||
->label('Meta (Optional)')
|
||||
->keyPlaceholder('Name')
|
||||
->valuePlaceholder('Content'),
|
||||
Textarea::make('custom_header')->rows(6)->label('Custom Header (Optional)'),
|
||||
|
||||
|
||||
]),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('post')->searchable(),
|
||||
TextColumn::make('slug'),
|
||||
TextColumn::make('category.name'),
|
||||
IconColumn::make('is_published')->label('Published')->boolean(),
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At'),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
SelectFilter::make('is_published')
|
||||
->label('Status')
|
||||
->options([
|
||||
0 => 'Draft',
|
||||
1 => 'Published',
|
||||
]),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListBlogs::route('/'),
|
||||
'create' => Pages\CreateBlog::route('/create'),
|
||||
'edit' => Pages\EditBlog::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
21
app/Filament/Resources/BlogResource/Pages/CreateBlog.php
Normal file
21
app/Filament/Resources/BlogResource/Pages/CreateBlog.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\BlogResource\Pages;
|
||||
|
||||
use App\Filament\Resources\BlogResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateBlog extends CreateRecord
|
||||
{
|
||||
protected static string $resource = BlogResource::class;
|
||||
|
||||
protected function getCreatedNotification(): ?Notification
|
||||
{
|
||||
return Notification::make()
|
||||
->success()
|
||||
->title('Post created')
|
||||
->body('Post created successfully');
|
||||
}
|
||||
}
|
||||
32
app/Filament/Resources/BlogResource/Pages/EditBlog.php
Normal file
32
app/Filament/Resources/BlogResource/Pages/EditBlog.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\BlogResource\Pages;
|
||||
|
||||
use App\Filament\Resources\BlogResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditBlog extends EditRecord
|
||||
{
|
||||
protected static string $resource = BlogResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
protected function getRedirectUrl(): ?string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getSavedNotification(): ?Notification
|
||||
{
|
||||
return Notification::make()
|
||||
->success()
|
||||
->title('Post updated')
|
||||
->body('Post updated successfully');
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/BlogResource/Pages/ListBlogs.php
Normal file
19
app/Filament/Resources/BlogResource/Pages/ListBlogs.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\BlogResource\Pages;
|
||||
|
||||
use App\Filament\Resources\BlogResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListBlogs extends ListRecords
|
||||
{
|
||||
protected static string $resource = BlogResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
86
app/Filament/Resources/CategoryResource.php
Normal file
86
app/Filament/Resources/CategoryResource.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\CategoryResource\Pages;
|
||||
use App\Filament\Resources\CategoryResource\RelationManagers;
|
||||
use App\Models\Category;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CategoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Category::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-ticket';
|
||||
|
||||
protected static ?string $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->live(1)
|
||||
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
||||
TextInput::make('slug')->required(),
|
||||
Select::make('is_active')
|
||||
->options([
|
||||
0 => 'Inactive',
|
||||
1 => 'Active',
|
||||
])
|
||||
->columnSpanFull()
|
||||
->required()
|
||||
->default(1)
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name'),
|
||||
TextColumn::make('slug'),
|
||||
IconColumn::make('is_active')->label('Active')->boolean(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCategories::route('/'),
|
||||
'create' => Pages\CreateCategory::route('/create'),
|
||||
'edit' => Pages\EditCategory::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCategory extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCategory extends EditRecord
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCategories extends ListRecords
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
90
app/Filament/Resources/MenuResource.php
Normal file
90
app/Filament/Resources/MenuResource.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\MenuResource\Pages;
|
||||
use App\Filament\Resources\MenuResource\RelationManagers;
|
||||
use App\Models\Menu;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class MenuResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Menu::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-bars-3-bottom-left';
|
||||
|
||||
protected static ?string $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
$menus = Menu::Pluck('name', 'id')->toArray();
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Menu Name')
|
||||
->required(),
|
||||
TextInput::make('url')
|
||||
->label('URL')
|
||||
->url()
|
||||
->required(),
|
||||
Select::make('parent')
|
||||
->options($menus)
|
||||
->searchable()
|
||||
->columnSpanFull()
|
||||
->label('Parents (Optional)'),
|
||||
Toggle::make('new_tab')
|
||||
->default(1)
|
||||
->label('Open in new tab'),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name'),
|
||||
TextColumn::make('url')->label('URL'),
|
||||
TextColumn::make('parentname.name')->label('Parent Name'),
|
||||
IconColumn::make('new_tab')->label('Open in New Tab')->boolean()
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListMenus::route('/'),
|
||||
'create' => Pages\CreateMenu::route('/create'),
|
||||
'edit' => Pages\EditMenu::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
21
app/Filament/Resources/MenuResource/Pages/CreateMenu.php
Normal file
21
app/Filament/Resources/MenuResource/Pages/CreateMenu.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MenuResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MenuResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateMenu extends CreateRecord
|
||||
{
|
||||
protected static string $resource = MenuResource::class;
|
||||
|
||||
protected function getCreatedNotification(): ?Notification
|
||||
{
|
||||
return Notification::make()
|
||||
->success()
|
||||
->title('Menu created')
|
||||
->body('Menu created successfully');
|
||||
}
|
||||
}
|
||||
32
app/Filament/Resources/MenuResource/Pages/EditMenu.php
Normal file
32
app/Filament/Resources/MenuResource/Pages/EditMenu.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MenuResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MenuResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditMenu extends EditRecord
|
||||
{
|
||||
protected static string $resource = MenuResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
protected function getRedirectUrl(): ?string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getSavedNotification(): ?Notification
|
||||
{
|
||||
return Notification::make()
|
||||
->success()
|
||||
->title('Menu updated')
|
||||
->body('Menu updated successfully');
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/MenuResource/Pages/ListMenus.php
Normal file
19
app/Filament/Resources/MenuResource/Pages/ListMenus.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MenuResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MenuResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListMenus extends ListRecords
|
||||
{
|
||||
protected static string $resource = MenuResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
131
app/Filament/Resources/PageResource.php
Normal file
131
app/Filament/Resources/PageResource.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\PageResource\Pages;
|
||||
use App\Filament\Resources\PageResource\RelationManagers;
|
||||
use App\Models\Page;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Set;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
|
||||
class PageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Page::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document';
|
||||
|
||||
protected static ?string $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
$pages = Page::Pluck('title', 'id')->toArray();
|
||||
|
||||
return $form
|
||||
->schema([
|
||||
|
||||
Section::make('Page Information')
|
||||
->description('Add a new page')
|
||||
->schema([
|
||||
TextInput::make('title')->label('Page Title')
|
||||
->required()
|
||||
->live(1)
|
||||
->columnSpanFull()
|
||||
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
||||
TextInput::make('slug')->required()->columnSpan(3),
|
||||
Select::make('is_published')
|
||||
->options([
|
||||
0 => 'Draft',
|
||||
1 => 'Published'
|
||||
])
|
||||
->default(1)
|
||||
->required()
|
||||
->searchable()
|
||||
->label('Status')
|
||||
->columnSpan(1),
|
||||
RichEditor::make('content')->label('Page Content')->columnSpanFull(),
|
||||
FileUpload::make('page_image')
|
||||
->label('Custom Image (Optional)')
|
||||
->directory('media/pages')
|
||||
->columnSpanFull()
|
||||
->preserveFilenames()
|
||||
->image()
|
||||
->maxSize(2048),
|
||||
])
|
||||
->columns(4),
|
||||
|
||||
Section::make('Customize Page')
|
||||
->description('Modifiy Page SEO and Meta Information')
|
||||
->schema([
|
||||
KeyValue::make('meta')
|
||||
->label('Meta (Optional)')
|
||||
->keyPlaceholder('Name')
|
||||
->valuePlaceholder('Content')
|
||||
->reorderable(),
|
||||
Select::make('parent')->options($pages)->label('Parents (Optional)'),
|
||||
Textarea::make('custom_header')->rows(6)->label('Custom Header (Optional)'),
|
||||
]),
|
||||
|
||||
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')->searchable(),
|
||||
TextColumn::make('slug'),
|
||||
IconColumn::make('is_published')->label('Published')->boolean(),
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At'),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPages::route('/'),
|
||||
'create' => Pages\CreatePage::route('/create'),
|
||||
'edit' => Pages\EditPage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
21
app/Filament/Resources/PageResource/Pages/CreatePage.php
Normal file
21
app/Filament/Resources/PageResource/Pages/CreatePage.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PageResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PageResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getCreatedNotification(): ?Notification
|
||||
{
|
||||
return Notification::make()
|
||||
->success()
|
||||
->title('Page created')
|
||||
->body('Page created successfully');
|
||||
}
|
||||
}
|
||||
32
app/Filament/Resources/PageResource/Pages/EditPage.php
Normal file
32
app/Filament/Resources/PageResource/Pages/EditPage.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PageResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PageResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPage extends EditRecord
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
protected function getRedirectUrl(): ?string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getSavedNotification(): ?Notification
|
||||
{
|
||||
return Notification::make()
|
||||
->success()
|
||||
->title('Page updated')
|
||||
->body('Page updated successfully');
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/PageResource/Pages/ListPages.php
Normal file
19
app/Filament/Resources/PageResource/Pages/ListPages.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PageResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PageResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPages extends ListRecords
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
40
app/Http/Middleware/CheckPageSlug.php
Normal file
40
app/Http/Middleware/CheckPageSlug.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckPageSlug
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$slug = $request->route('slug');
|
||||
|
||||
$publicPath = public_path($slug);
|
||||
|
||||
if (file_exists($publicPath) && is_file($publicPath) && pathinfo($slug, PATHINFO_EXTENSION) === 'php') {
|
||||
ob_start();
|
||||
include($publicPath);
|
||||
$content = ob_get_clean();
|
||||
ob_flush();
|
||||
return response($content);
|
||||
}
|
||||
|
||||
if (file_exists($publicPath) && is_file($publicPath)) {
|
||||
return response()->file($publicPath);
|
||||
}
|
||||
|
||||
if (is_dir($publicPath)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
22
app/Livewire/Blog.php
Normal file
22
app/Livewire/Blog.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Category;
|
||||
use Livewire\Component;
|
||||
|
||||
class Blog extends Component
|
||||
{
|
||||
public $postDetail;
|
||||
public $category;
|
||||
|
||||
public function mount($slug) {
|
||||
$this->postDetail = \App\Models\Blog::where('slug', $slug)->firstOrFail();
|
||||
$this->category = Category::where('id', $this->postDetail->category_id)->first();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.blog')->with('postDetail', $this->postDetail)->with('category', $this->category);
|
||||
}
|
||||
}
|
||||
28
app/Livewire/Page.php
Normal file
28
app/Livewire/Page.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Page extends Component
|
||||
{
|
||||
public $slug;
|
||||
|
||||
public function mount($slug)
|
||||
|
||||
{
|
||||
$this->slug = $slug;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$page = \App\Models\Page::where('slug', $this->slug)->firstOrFail();
|
||||
|
||||
if ($page->is_published == false ) {
|
||||
abort(404);
|
||||
}
|
||||
return view('livewire.page', [
|
||||
'page' => $page,
|
||||
]);
|
||||
}
|
||||
}
|
||||
32
app/Models/Blog.php
Normal file
32
app/Models/Blog.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Blog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'post',
|
||||
'slug',
|
||||
'content',
|
||||
'meta',
|
||||
'custom_header',
|
||||
'post_image',
|
||||
'is_published',
|
||||
'category_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'meta' => 'json'
|
||||
];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
}
|
||||
22
app/Models/Category.php
Normal file
22
app/Models/Category.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'is_active'
|
||||
];
|
||||
|
||||
public function blogs(): HasMany {
|
||||
return $this->hasMany(Blog::class);
|
||||
}
|
||||
}
|
||||
@@ -72,15 +72,9 @@ class Email extends Model
|
||||
$allowed = explode(',', 'doc,docx,xls,xlsx,ppt,pptx,xps,pdf,dxf,ai,psd,eps,ps,svg,ttf,zip,rar,tar,gzip,mp3,mpeg,wav,ogg,jpeg,jpg,png,gif,bmp,tif,webm,mpeg4,3gpp,mov,avi,mpegs,wmv,flx,txt');
|
||||
$connection = \App\Models\Email::connectMailBox();
|
||||
$mailbox = $connection->getMailbox('INBOX');
|
||||
// $search = new SearchExpression();
|
||||
// $email = "gegsaf@e-pool.co.uk";
|
||||
// $search->addCondition(new To($email));
|
||||
|
||||
$messages = $mailbox->getMessages();
|
||||
//$messages = $mailbox->getMessages($search, \SORTDATE, true);
|
||||
|
||||
$result = '';
|
||||
|
||||
foreach ($messages as $message) {
|
||||
|
||||
$sender = $message->getFrom();
|
||||
@@ -360,8 +354,6 @@ class Email extends Model
|
||||
|
||||
public static function deleteBulkMailboxes()
|
||||
{
|
||||
|
||||
|
||||
$foldersToClean = ['Trash', 'ZDUMP', 'INBOX'];
|
||||
$cutoff = (new \DateTime())->modify('-3 hours');
|
||||
$totalDeleted = 0;
|
||||
@@ -413,7 +405,6 @@ class Email extends Model
|
||||
public static function mailToDBStatus(): bool
|
||||
{
|
||||
$latestRecord = self::orderBy('timestamp', 'desc')->first();
|
||||
|
||||
if (!$latestRecord) {
|
||||
return false;
|
||||
}
|
||||
@@ -421,7 +412,6 @@ class Email extends Model
|
||||
$currentTime = Carbon::now('UTC');
|
||||
$lastRecordTime = Carbon::parse($latestRecord->timestamp);
|
||||
|
||||
// Check if the last record was added within the last 1 hour
|
||||
if ($lastRecordTime->diffInMinutes($currentTime) < 5) {
|
||||
return true;
|
||||
}
|
||||
|
||||
23
app/Models/Menu.php
Normal file
23
app/Models/Menu.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'url',
|
||||
'new_tab',
|
||||
'parent'
|
||||
];
|
||||
|
||||
public function parentname()
|
||||
{
|
||||
return $this->belongsTo(Menu::class, 'parent');
|
||||
}
|
||||
}
|
||||
26
app/Models/Page.php
Normal file
26
app/Models/Page.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Page extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'slug',
|
||||
'content',
|
||||
'parent',
|
||||
'meta',
|
||||
'custom_header',
|
||||
'page_image',
|
||||
'is_published'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'meta' => 'json'
|
||||
];
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Blog;
|
||||
use App\Models\Menu;
|
||||
use DB;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
@@ -20,12 +22,20 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$settings = cache()->remember('app_settings', now()->addMinutes(1), function () {
|
||||
$settings = cache()->remember('app_settings', now()->addSecond(1), function () {
|
||||
return (array) DB::table('settings')->find(1);
|
||||
});
|
||||
$menus = Menu::all();
|
||||
$blogs = Blog::where(['is_published' => 1])->get();
|
||||
if ($settings) {
|
||||
config(['app.settings' => (array) $settings]);
|
||||
}
|
||||
if ($menus) {
|
||||
config(['app.menus' => $menus]);
|
||||
}
|
||||
if ($blogs) {
|
||||
config(['app.blogs' => $blogs]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user