2017-02-19 11 views
0

単語ファイルをレポートとして作成したいと思います。私はテーブルからすべてのデータをフェッチしてワードファイルに入れたいが、ファイルにデータを保存できない。私はlaravel 5.2でやっています。ファイルが作成され、ダウンロードされていますが、データベースからのデータは保存されません。あなたは、ブレードを使用していないのはなぜlaravelのデータベースから単語ファイルにデータを保存するには

public function downloadAbleFile(Request $request){ 
    //Fetching all records based on projectid 
    $project_id = $request->input('project_id'); 
    $questiondetails = DB::table('questionnair')->where('project_id','=',$project_id)->get(); 

    $headers = array(
     "Content-type"=>"text/html", 
     "Content-Disposition"=>"attachment;Filename=report.doc" 
    ); 

    $content = '<html> 
       <head> 
       <meta charset="utf-8"> 
       </head> 
       <body> 
        <p> 
         <table> 
         <thead> 
         <tr> 
         <th>Project ID</th> 
         <th>Question Number</th> 
         <th>User ID</th> 
         <th>Answer</th> 
         <th>Status</th> 
         </tr> 
         </thead> 
         <tbody> 
         <?php 
          function project(){ 
          foreach ($questiondetails as $question){ 
           return(
            echo "<tr>"; 
            echo "<td>".$question->project_id."</td>"; 
            echo "<td>".$question->question_num."</td>"; 
            echo "<td>".$question->user_id."</td>"; 
            echo "<td>".$question->answer."</td>"; 
            echo "<td>".$question->status."</td>"; 
            echo "</tr>"; 
           ); 
          } 
         } 
         project(); 
         ?> 
         </tbody> 
         </table> 
        </p> 
       </body> 
       </html>'; 

    return Response::make($content,200, $headers); 
} 

答えて

0

- みんなありがとう は、ここに私のコントローラのコードですか?お使いのコントローラでこの

を試してみてください :あなたのビューで

public function downloadAbleFile(Request $request){ 
    $project_id  = $request->input('project_id'); 
    $questiondetails = DB::table('questionnair')->where('project_id','=',$project_id)->get(); 

    $headers = array(
     "Content-type"  => "text/html", 
     "Content-Disposition" => "attachment;Filename=report.doc" 
    ); 

    $content = View::make('path.view', [ 
        'questiondetails' => $questiondetails, 
       ])->render(); 

    return Response::make($content,200, $headers); 
} 

<html> 
    <head> 
     <meta charset="utf-8"> 
    </head> 
    <body> 
     <br> 
     <table> 
      <thead> 
       <tr> 
        <th>Project ID</th> 
        <th>Question Number</th> 
        <th>User ID</th> 
        <th>Answer</th> 
        <th>Status</th> 
       </tr> 
      </thead> 
      <tbody> 
       @foreach($questiondetails as $question) 
       <tr> 
        <td>{{ $question->project_id }}</td> 
        <td>{{ $question->question_num }}</td> 
        <td>{{ $question->user_id }}</td> 
        <td>{{ $question->answer }}</td> 
        <td>{{ $question->status }}</td> 
       </tr> 
       @endforeach 
      </tbody> 
     </table> 
     <br> 
    </body> 
</html> 
関連する問題