16
16
use Illuminate \Queue \SerializesModels ;
17
17
use Illuminate \Support \Arr ;
18
18
use Illuminate \Support \Facades \Auth ;
19
+ use Illuminate \Support \Facades \File ;
19
20
use Illuminate \Support \Str ;
20
21
use PhpOffice \PhpSpreadsheet \Shared \Date ;
21
22
use Yajra \DataTables \Html \Column ;
@@ -53,6 +54,9 @@ public function __construct(array $dataTable, array $request, $user = null)
53
54
* Execute the job.
54
55
*
55
56
* @return void
57
+ * @throws \Box\Spout\Common\Exception\IOException
58
+ * @throws \Box\Spout\Common\Exception\UnsupportedTypeException
59
+ * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException
56
60
*/
57
61
public function handle ()
58
62
{
@@ -70,14 +74,20 @@ public function handle()
70
74
$ dataTable = app ()->call ([$ oTable , 'dataTable ' ], compact ('query ' ));
71
75
$ dataTable ->skipPaging ();
72
76
77
+ $ exportPath = storage_path ('app/exports ' );
78
+
79
+ if (! File::isDirectory ($ exportPath )) {
80
+ File::makeDirectory ($ exportPath );
81
+ }
82
+
73
83
$ type = Str::startsWith (request ('exportType ' ), Type::CSV ) ? Type::CSV : Type::XLSX ;
74
84
$ writer = WriterEntityFactory::createWriter ($ type );
75
- $ writer ->openToFile (storage_path ( ' app/exports/ ' . $ this ->batchId . '. ' . $ type) );
85
+ $ writer ->openToFile ($ exportPath . ' / ' . $ this ->batchId . '. ' . $ type );
76
86
77
87
$ columns = $ oTable ->html ()->getColumns ()->filter ->exportable ;
78
88
$ writer ->addRow (
79
89
WriterEntityFactory::createRowFromArray (
80
- $ columns ->map (fn ($ column ) => strip_tags ($ column ['title ' ]))->toArray ()
90
+ $ columns ->map (fn ($ column ) => strip_tags ($ column ['title ' ]))->toArray ()
81
91
)
82
92
);
83
93
@@ -123,7 +133,7 @@ public function handle()
123
133
*/
124
134
protected function wantsDateFormat (Column $ column ): bool
125
135
{
126
- if (!isset ($ column ['exportFormat ' ])) {
136
+ if (! isset ($ column ['exportFormat ' ])) {
127
137
return false ;
128
138
}
129
139
0 commit comments