2016-01-19 81 views
2

控制器:響應::下載錯誤laravel

public function download(){ 

$headers = array('Content-Type' => 'text/csv'); 
return Response::download('download.csv', 'download.csv', $headers)->setContentDisposition('inline'); 

} 

篩選:

$response->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); 

錯誤:

[2016-01-19 15:34:29] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::header()' in C:\xampp\htdocs\development\app\filters.php:60 
    Stack trace: 
    #0 [internal function]: Illuminate\Exception\Handler->handleShutdown() 
    #1 {main} [] [] 

我不知道如何解決這種的問題。我已經嘗試過this,但仍然無法正常工作。

+0

你爲什麼標籤齊備Laravel版本?我假設你正在使用Laravel 4,因爲你已經指定了使用過濾器? –

+0

@MikeRockett對不起。也許有人可以在Laravel 5的頭文件中幫助我。 – aldrin27

回答

0

https://github.com/palanik/lumen-cors/issues/9

/** 
    * Handle an incoming request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param \Closure $next 
    * @return mixed 
    */ 
    public function handle($request, Closure $next) { 

     if ($request->isMethod('OPTIONS')) { 
      $response = new Response("", 200); 
     } 
     else { 
      $response = $next($request); 
     } 

     // Added this to fix the image download problem 
     // Only set Cors if its not een image 
     if(strpos($response->headers->get('content-type'), 'image') === false) { 
      $this->setCorsHeaders($request, $response); 
     } 

     return $response; 
    }