Airport Guide Documentation

TransportationController extends BaseController
in package

Public Transportation Management Controller

This controller handles all operations related to public transportation services at airports. It provides CRUD operations for managing transportation companies, their contact information, routes, pricing, and associated airport data. The controller includes features for listing, creating, editing, viewing, and deleting transportation records with proper validation, image processing, and admin activity logging.

Features:

  • DataTables integration with search and filtering
  • Image upload with thumbnail generation (200x200 with aspect ratio)
  • Airport code parsing and validation
  • Security validation with MD5 hash verification
  • Admin activity logging for all operations
  • City name formatting and processing
  • Price management and route information
  • Product URL and company description handling
  • Organized file storage structure (YYYY/MM)
Tags
author

Airport Guide System

version
1.0
since
2024

Table of Contents

Methods

__construct()  : void
Constructor for TransportationController
create()  : View
Show the form for creating a new public transportation resource
deleteImage()  : void
Delete transportation image files
destroy()  : RedirectResponse
Remove the specified public transportation resource from storage
edit()  : View|RedirectResponse
Show the form for editing the specified public transportation resource
getCity()  : JsonResponse
Get cities based on airport code
index()  : View|DataTable
Display a listing of public transportation resources
show()  : void
Display the specified public transportation resource
store()  : RedirectResponse
Store a newly created public transportation resource in storage
update()  : RedirectResponse
Update the specified public transportation resource in storage

Methods

__construct()

Constructor for TransportationController

public __construct() : void

Initializes the controller by checking user authentication and permissions. Redirects to login if user is not authenticated or lacks proper permissions.

create()

Show the form for creating a new public transportation resource

public create(Request $request) : View

Displays the create form with necessary data for adding a new transportation service. Prepares dropdown lists for airports, states, and other required fields.

Parameters
$request : Request

The HTTP request object

Tags
example

GET /admin/transportation/create

Return values
View

Returns the create form view

deleteImage()

Delete transportation image files

public deleteImage(int $id) : void

Removes image files associated with a transportation record from the file system. Deletes both the main image and its thumbnail, then updates the database record to clear the image references.

Parameters
$id : int

The ID of the transportation record

Tags
example

POST /admin/transportation/delete-image/123

Response: true // or false

Return values
void

Outputs "true" on success or "false" on failure

destroy()

Remove the specified public transportation resource from storage

public destroy(int $id) : RedirectResponse

Deletes a transportation record and associated image files, then creates an admin activity log entry. Performs cleanup of both main images and thumbnails from the file system.

Parameters
$id : int

The ID of the transportation record to delete

Tags
example

DELETE /admin/transportation/123

Return values
RedirectResponse

Redirects to index with success message

edit()

Show the form for editing the specified public transportation resource

public edit(int $id, Request $request) : View|RedirectResponse

Displays the edit form for an existing transportation record with security validation. Includes MD5 hash verification to prevent unauthorized access and maintains pagination state and search filters in the form.

Parameters
$id : int

The ID of the transportation record to edit

$request : Request

The HTTP request object containing security key and pagination data

Tags
example

GET /admin/transportation/123/edit?key=abc123&page_no=2

Return values
View|RedirectResponse

Returns edit form or redirects on security failure

getCity()

Get cities based on airport code

public getCity(Request $request) : JsonResponse

Retrieves available cities for a specific airport code. This method supports both creating new records (no ID provided) and editing existing records (ID provided). For existing records, it also returns the current city name.

Parameters
$request : Request

The HTTP request object containing airport information

Tags
example

// For new record GET /admin/transportation/get-city?airport=John F. Kennedy International Airport (JFK)

Response: { "cities": [ {"city_name": "New York"}, {"city_name": "Brooklyn"}, {"city_name": "Queens"} ] }

// For existing record GET /admin/transportation/get-city?id=123&airport=John F. Kennedy International Airport (JFK)

Response: { "name": "New York", "cities": [ {"city_name": "New York"}, {"city_name": "Brooklyn"}, {"city_name": "Queens"} ] }

Return values
JsonResponse

Returns JSON with cities array and optional current city name

index()

Display a listing of public transportation resources

public index(Request $request) : View|DataTable

This method handles both AJAX and regular requests for displaying transportation data. For AJAX requests, it returns DataTables formatted data with search and filtering capabilities. For regular requests, it returns a view with pagination and search filters.

Features:

  • Pagination support with configurable page size
  • Search filtering by company name, airport name, airport code, and city
  • DataTables integration for enhanced user experience
  • Action buttons for view, edit, and delete operations
  • Case-insensitive search with ILIKE and UPPER functions
  • Filter state preservation in action URLs
Parameters
$request : Request

The HTTP request object containing search parameters and pagination data

Tags
example

// Regular request GET /admin/transportation

// AJAX request with search filters GET /admin/transportation?ajax=1&company_name=ABC&airport_code=JFK&city=New York

Return values
View|DataTable

Returns view for regular requests or DataTable for AJAX

show()

Display the specified public transportation resource

public show(int $id, Request $request) : void

Shows detailed information about a specific transportation record in HTML format. This method is typically called via AJAX to display data in a modal window. Only displays fields that have values (non-empty).

Parameters
$id : int

The ID of the transportation record to display

$request : Request

The HTTP request object

Tags
example

GET /admin/transportation/123

Output:

Airport NameJohn F. Kennedy International Airport
Company NameABC Transportation
Route NameDowntown Express
Price25.00
Return values
void

Outputs HTML content directly to the response

store()

Store a newly created public transportation resource in storage

public store(Request $request) : RedirectResponse

Validates and stores a new transportation record with comprehensive features:

  • Validates required fields (airport_name)
  • Handles image upload with organized directory structure (YYYY/MM)
  • Creates thumbnails using Intervention Image library (200x200 with aspect ratio)
  • Parses airport information from formatted string
  • Processes city names with formatting (handles hyphenated names)
  • Creates admin activity log entry
  • Supports pricing, route information, and product URLs
Parameters
$request : Request

The HTTP request object containing form data and file uploads

Tags
throws
ValidationException

When validation fails

example

POST /admin/transportation

Request data: { "airport_name": "John F. Kennedy International Airport (JFK)", "company_name": "ABC Transportation", "city": "new-york", "state": "NY", "route_name": "Downtown Express", "product_url": "https://abctransport.com", "company_desc": "Reliable public transportation service", "price": "25.00", "file": [image file] }

Return values
RedirectResponse

Redirects to index with success message

update()

Update the specified public transportation resource in storage

public update(Request $request, int $id) : RedirectResponse

Updates an existing transportation record with validation and security features:

  • Validates required fields
  • Handles image upload with organized directory structure (YYYY/MM)
  • Creates thumbnails using Intervention Image library (200x200 with aspect ratio)
  • Parses airport information from formatted string
  • Processes city names with formatting (handles hyphenated names)
  • Creates admin activity log entry
  • Maintains pagination and search filter state
  • Supports pricing, route information, and product URLs
  • Handles image replacement with cleanup of old files
Parameters
$request : Request

The HTTP request object containing form data and file uploads

$id : int

The ID of the transportation record to update

Tags
throws
ValidationException

When validation fails

example

PUT /admin/transportation/123

Request data: { "airport_name": "John F. Kennedy International Airport (JFK)", "company_name": "Updated ABC Transportation", "city": "new-york", "state": "NY", "route_name": "Updated Downtown Express", "product_url": "https://updatedabctransport.com", "company_desc": "Updated transportation service", "price": "30.00", "file": [new image file], "old_transport_pic": "old_image.jpg", "photo_path": "uploads/transportation/2024/01/" }

Return values
RedirectResponse

Redirects to index with success message and preserved filters


        
On this page

Search results