I want to use maatwebsite/excel on laravel 5.7 and I'm currently stuck for some time on a syntax error, can you help me?
"syntax error, unexpected '}'" line 28 :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Excel;
class ExportExcelController extends Controller
{
function Export()
{
$customer_data = DB::table('qualys')->get();
return view('export_excel')->with('customer_data', $customer_data);
}
function excel()
{
$customer_data = DB::table('qualys')->get()->toArray();
$customer_data[] = array('qid','ip');
foreach($customer_data as $customer)
{
$customer_array[] = array(
'qid' => $customer -> qid,
'ip' => $customer -> ip
)
}
Excel::create('customer data', function($excel) use ($customer_array)
{
$excel->setTitle('customer Data');
$excel->sheet('Customer Data', function($sheet) use ($customer_array)
{
$sheet->fromeArray($customer_array, null, 'A1', false, false);
});
})->download('xlsx');
}
}
Sincerely
I think the cause lies in your variables in the foreach
. There should not be a space between object and property, like this:
$customer_array[] = array(
'qid' => $customer->qid,
'ip' => $customer->ip
);
(Note the semicolon at the end)
you should update your excel function code like:
function excel()
{
$customer_data = DB::table('qualys')->get()->toArray();
$customer_data[] = array('qid','ip');
foreach($customer_data as $customer)
{
$customer_array[] = array(
'qid' => $customer -> qid,
'ip' => $customer -> ip
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.