Синтаксис ошибок laravel 5.7 maatwebsite / excel - PullRequest
0 голосов
/ 19 декабря 2018

Я хочу использовать maatwebsite / excel на laravel 5.7, и в настоящее время я застрял на некоторое время с синтаксической ошибкой, можете ли вы мне помочь?

"синтаксическая ошибка, неожиданная '}'" строка 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');
    }
}

С уважением

Ответы [ 2 ]

0 голосов
/ 19 декабря 2018

Я думаю, что причина кроется в ваших переменных в foreach.Между объектом и свойством не должно быть пробела, например:

$customer_array[] = array(
    'qid' => $customer->qid,
    'ip' => $customer->ip
);

(обратите внимание на точку с запятой в конце)

0 голосов
/ 19 декабря 2018

Вы должны обновить свой код функции Excel как:

   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
    );
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...