PHPackages                             mahmoud-m-abadi/excel-export-with-relations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mahmoud-m-abadi/excel-export-with-relations

ActiveProject[Database &amp; ORM](/categories/database)

mahmoud-m-abadi/excel-export-with-relations
===========================================

Laravel excel export with multiple relations

126PHP

Since Jul 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/mahmoud-m-abadi/Excel-export-with-relations)[ Packagist](https://packagist.org/packages/mahmoud-m-abadi/excel-export-with-relations)[ RSS](/packages/mahmoud-m-abadi-excel-export-with-relations/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Excel export with multiple relations
============================================

[](#laravel-excel-export-with-multiple-relations)

This package uses [maatwebsite/excel](https://github.com/Maatwebsite/Laravel-Excel) to make excel report.

Installation
------------

[](#installation)

To install package copy below link.
`composer require mahmoud-m-abadi/excel-export-with-relations`

### Requirement

[](#requirement)

- PHP Version &gt;= 7.3
- Laravel 8

Description
-----------

[](#description)

It's assumed that you have one User model, Post model and Post Comment Model. User has many posts and each post has many comments and you want to make an export report for User model along with all relations in one Excel file.

Now you can make a controller and use the below Export class from this package:

`MahmoudMAbadi\ExcelExportWithRelation\Exports\ExcelExportWithRelations`

Your target model to export must have `ModelExportableInterface` to prepare to export using this package. For example: If you want to make export from User model, you need to add `ModelExportableInterface` class to the UserModel. You can also use `ModelExportableTrait` to make relevant function or replace it to your own.

Actually, I've attached some example as Controllers, Models, Route. You can check the files and make sure you are doing process correctly.

Controller Example:

```
