On line guide/help
You are on page 4 of the online help. Navigate sequentially through the guide pages or search for a topic of interest to you.
Index Prev. NextMaster-Details report in Laravel
Build a master-details report using the Laravel framework
A Master/Details report is, for example, a sales order or an invoice. In this type of document, each report page contains data related to a single header or footer (1 master record row) and a series of detail data rows (detail record rows).
Using the library's data providers, you can define the data source to use as the master and details. The report will automatically loop through the possible values ββto generate the report using the data and will end when it has processed all of them.
In the specific case of Laravel, as an example, let's generate the sales order report, which you can also find in the reserved area. The example in the members' area uses PHP's standard MySQLi connector DataProviderMySQLi. Laraval interfaces with databases using the Eloquent ORM, so we'll use the DataProviderEloquent connector.
Creating a new Laravel Web Application with a custom controller button
Step-by-Step Guide. As a prerequisite, all the components needed to create and run a Laravel web project locally must have been installed. First, in a command shell, create a new Laravel project using the following command (please be patient, the command may take several minutes to execute):
composer create-project laravel/laravel my-report-app
Change directory:
cd my-report-app
Install the report library:
composer require alienproject/pdfreport
Create the Custom Controller. This controller will contain all the logic (the PHP code) needed to generate the report using the PDF Report library. Generate a controller named ReportController using this command:
php artisan make:controller ReportController
This creates a file at app/Http/Controllers/ReportController.php Open file app/Http/Controllers/ReportController.php using Visual Studio Code or Notepad++ and add your build method like in the following code:
ReportController class with build public method
Be sure to copy the order.xml template file in the public folder. The template file is uploaded to the public folder only because it's sample code. When developing a production application, template files should be managed more securely by placing them in a different folder or loading them into a Text field in the database.
XML template file (order.xml)
Open the file routes/web.php and add a route for your controller method:
Route for ReportController class
Edit resources/views/welcome.blade.php to add your button (add the following code after the "Deploy now" button):
Button to execute report build method
Edit the .env file to connect to your local development/test database (at the bottom of this page you will find the link to download the example SQL file needed to generate the tables and views with the test data in your MySQL database):
# Connect to local development/test database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_schema_name_here
DB_USERNAME=your_database_username_here
DB_PASSWORD=your_database_password_here
Reset cache using the following command:
php artisan config:clear
Creating Laravel default tables in the test database:
php artisan session:table
php artisan migrate
Now start your local PHP server and development database server (e.g. XAMPP or Laragon). Launch your browser (e.g., Chrome) and type the address of the home page of your newly created web app. It should look something like: http://localhost/my-report-app. If all goes well, the classic window of a new Laragon application will appear with the addition of a button that, when clicked, generates the PDF report.