Skip to content
Md Sazzadul islam edited this page May 31, 2024 · 1 revision

Laravel Dynamic Report Generator

Welcome to the Laravel Dynamic Report Generator wiki! This package allows users to create, save, and execute custom SQL queries dynamically from the browser. Below you'll find documentation to help you get started.

Table of Contents

  1. Installation
  2. Configuration
  3. Usage
  4. Middleware
  5. Routes
  6. Controllers
  7. Views

Installation

Step 1: Composer

Install the package via Composer:

composer require devforest/laravel-dynamic-report-generator

Step 2: Service Provider

Add the ReportGeneratorServiceProvider to your config/app.php file:

'providers' => [
    // ...
    DevForest\ReportGeneratorServiceProvider::class,
],

Step 3: Publish Assets

Publish the required assets:

php artisan vendor:publish --provider="DevForest\ReportGeneratorServiceProvider" --tag=migrations
php artisan vendor:publish --provider="DevForest\ReportGeneratorServiceProvider" --tag=public

Step 4: Migrate

Run the migrations to create the necessary database tables:

php artisan migrate

Configuration

No additional configuration is required out of the box. The package uses Laravel's default database and routing configurations.

Usage

Accessing the Interface

Once installed, you can access the report generator interface at:

http://your-app-url/report-generator

Creating a Report

Screenshot_1

  1. Navigate to the report generator interface.
  2. Enter the SQL query you wish to execute (note that dangerous queries like CREATE, ALTER, TRUNCATE, DROP, INSERT, UPDATE, and DELETE are prohibited).
  3. Provide a name for your report.
  4. Click the "Save" button to save the report.

Viewing Reports

Screenshot_2 To view the list of saved reports, navigate to:

http://your-app-url/report-generator/reports

Executing Reports

Screenshot_3

  1. From the list of reports, click on the report you wish to execute.
  2. The results will be displayed in a paginated format.
  3. You can navigate through the pages to view all results.

Middleware

This package uses the ShareErrorsFromSessionMiddleware middleware to handle session errors. It is aliased as share.errors in your routes.

Routes

The package loads its routes from the routes/web.php file. Below are the key routes used:

  • GET /report-generator: Display the report generator interface.
  • POST /report-generator/save: Save a new report.
  • GET /report-generator/reports: List all saved reports.
  • GET /report-generator/execute/{slug}: Execute a saved report.
  • GET /report-generator/get-columns/{table}: Get columns and foreign keys of a table.

Controllers

ReportController

  • index: Displays the report generator interface.
  • save: Validates and saves a new report.
  • listReports: Lists all saved reports.
  • execute: Executes a saved report with pagination.
  • getColumns: Retrieves columns and foreign keys of a specified table.

Views

The package's views are located in resources/views/vendor/laravel-dynamic-report-generator. The key views are:

  • index.blade.php: Main interface for creating reports.
  • reports.blade.php: Lists all saved reports.
  • result.blade.php: Displays the results of an executed report.

Feel free to explore and customize these views to fit your application's needs.

Conclusion

The Laravel Dynamic Report Generator is a powerful tool for dynamically creating and executing SQL queries from the browser. For any issues or contributions, please refer to the GitHub repository. Happy reporting!