Last active
April 18, 2021 15:42
-
-
Save Qoraiche/f2d70ae2595217c94e835fd6b3b44ccb to your computer and use it in GitHub Desktop.
Laravel Excel Export Model Resource
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Exports; | |
use App\Http\Resources\ModelResource; | |
use App\Models\Model; | |
use Maatwebsite\Excel\Concerns\FromArray; | |
use Maatwebsite\Excel\Concerns\Exportable; | |
use Maatwebsite\Excel\Concerns\WithHeadings; | |
class ModelExport implements FromArray, WithHeadings | |
{ | |
use Exportable; | |
private $id; | |
/** | |
* ModelExport constructor. | |
* @param int $id | |
*/ | |
public function __construct(int $id) | |
{ | |
$this->id = $id; | |
} | |
public function array(): array | |
{ | |
return (array)(new ModelResource(Model::find(1))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment