SectionController
extends BaseController
in package
Section Management Controller
This controller handles all operations related to CMS sections management. It provides CRUD operations for managing website sections, including content, images, and layout components. The controller includes features for listing, creating, editing, and deleting section records with proper validation, image processing, and admin activity logging.
Features:
- Image upload and processing with thumbnail generation
- Content management for various section types
- Security validation with MD5 hash verification
- Admin activity logging for all operations
- Search functionality with pagination
Tags
Table of Contents
Methods
- __construct() : void
- Constructor for SectionController
- create() : View
- Show the form for creating a new section resource
- destroy() : RedirectResponse
- Remove the specified section resource from storage
- edit() : View|RedirectResponse
- Show the form for editing the specified section resource
- index() : View
- Display a listing of section resources
- store() : RedirectResponse
- Store a newly created section resource in storage
- update() : RedirectResponse|string
- Update the specified section resource in storage
Methods
__construct()
Constructor for SectionController
public
__construct() : void
Initializes the controller by checking user authentication and permissions. Redirects to login if user is not authenticated or lacks proper permissions. Includes HTTPS detection and URL construction for security validation.
create()
Show the form for creating a new section resource
public
create(Request $request) : View
Displays the create form for adding a new section to the CMS. Prepares an empty Section model instance for the form.
Parameters
- $request : Request
-
The HTTP request object
Tags
Return values
View —Returns the create form view
destroy()
Remove the specified section resource from storage
public
destroy(int $id) : RedirectResponse
Deletes a section record and associated image files from storage. Performs cleanup of both original images and thumbnails. Creates admin activity log entry for the deletion.
Features:
- File cleanup (original and thumbnail images)
- Admin activity logging
- Soft/hard delete handling
Parameters
- $id : int
-
The ID of the section record to delete
Tags
Return values
RedirectResponse —Redirects to index with success message
edit()
Show the form for editing the specified section resource
public
edit(int $id, Request $request) : View|RedirectResponse
Displays the edit form for an existing section record with security validation. Includes MD5 hash verification to prevent unauthorized access.
Parameters
- $id : int
-
The ID of the section record to edit
- $request : Request
-
The HTTP request object containing security key
Tags
Return values
View|RedirectResponse —Returns edit form or redirects on security failure
index()
Display a listing of section resources
public
index(Request $request) : View
This method handles the display of all section records with search functionality. Provides pagination support and search filtering by section title.
Features:
- Pagination with configurable page size
- Search functionality by section title
- Sortable results
- Session management
Parameters
- $request : Request
-
The HTTP request object containing search parameters
Tags
Return values
View —Returns the section listing view
store()
Store a newly created section resource in storage
public
store(Request $request) : RedirectResponse
Validates and stores a new section record with image processing capabilities. Handles file upload, image validation, thumbnail generation, and admin logging.
Features:
- File upload validation (JPEG, JPG, PNG, WebP)
- Automatic thumbnail generation (300x200 with aspect ratio)
- Image processing with Intervention Image library
- Admin activity logging
- Comprehensive data validation
Parameters
- $request : Request
-
The HTTP request object containing form data and file uploads
Tags
Return values
RedirectResponse —Redirects to index with success message
update()
Update the specified section resource in storage
public
update(Request $request, int $id) : RedirectResponse|string
Updates an existing section record with image processing and validation. Handles file upload, image replacement, thumbnail regeneration, and admin logging.
Features:
- Image replacement with old file cleanup
- Thumbnail regeneration
- File validation and processing
- Admin activity logging
- Comprehensive data validation
Parameters
- $request : Request
-
The HTTP request object containing form data and file uploads
- $id : int
-
The ID of the section record to update
Tags
Return values
RedirectResponse|string —Returns redirect or error string