前提・実現したいこと
laravelで名刺管理のためのアプリを作っています。
ログイン後、名刺リスト画面に行き、そこから名刺情報の検索・CSVダウンロード・新規登録を行う予定です。
list画面にて、何個かボタンを設定し、それを押すとpostが送信され、各新規登録やCSVダウンロードが行われるようにしたいです。
しかしlist画面にて新規登録ボタンやCSVダウンロードを押しても、新規登録とCSVファイルダウンロードができません。
var_dumpで調べたところ、post自体は飛んでいるので、Laravelのルート情報の設定か、関数の呼び出しがうまくいってないのかと思います。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
php
1 //最初のリスト画面を表示する 2 public function list() 3 { 4 global $meishilist; 5 $query = Meishi::query(); 6 $meishilist = $query->orderBy('id')->simplePaginate(50); 7 8 return view('list')->with('meishilist', $meishilist); 9 } 10 11 //list画面にて各ボタンが押された時の機能分け 12 public function postlist(Request $request) 13 { 14 #var_dump(Input::all()); 15 16 if (Input::get('namesearch')) 17 { 18 return $this->namesearch($request); 19 } elseif (Input::get('companysearch')) { 20 return $this->companysearch($request); 21 } elseif (Input::get('othersearch')) { 22 return $this->othersearch($request); 23 } elseif (Input::get('csvdownload')) { 24 return $this->csvdownload($meishilist); 25 } elseif (Input::get('newregister')) { 26 return $this->form($request); 27 } 28 } 29 30 //list画面での名前検索欄の機能・名刺情報「お名前」での検索を行う。 31 public function namesearch(Request $request) 32 { 33 global $meishilist; 34 $param = "$request->namesearch"; 35 $nameresult = Meishi::where('name', 'like', "%{$param}%")->simplePaginate(50); 36 $meishilist = $nameresult; 37 return view('list')->with('meishilist', $meishilist); 38 } 39 40 //list画面での会社名検索欄の機能・名刺情報「会社名」での検索を行う。 41 public function companysearch(Request $request) 42 { 43 global $meishilist; 44 $param = "$request->companysearch"; 45 $companyresult = Meishi::where('company', 'like', "%{$param}%")->simplePaginate(50); 46 $meishilist = $companyresult; 47 return view('list')->with('meishilist', $meishilist); 48 } 49 50 //名刺情報のうち「お名前」「会社情報」以外で検索を行う「その他検索」を行う。 51 public function othersearch(Request $request) 52 { 53 global $meishilist; 54 $param = "$request->othersearch"; 55 $otherresult = Meishi::where(DB::raw("concat(tel,address,email)"), 'LIKE', "%{$param}%")->simplePaginate(50); 56 $meishilist = $otherresult; 57 return view('list')->with('meishilist', $meishilist); 58 } 59 60 //CSVダウンロードボタンが押された場合 61 public function csvdownload(&$meishilist) 62 { 63 64 $array = $meishilist; 65 $file = new SplFileObject('test.csv','w'); 66 foreach ($array as $line) { 67 $file->fputcsv($line); 68 } 69 70 $filepath = 'test.csv'; 71 header('Content-Type: application/octet-stream'); 72 header('Content-Length: '.filesize($filepath)); 73 header('Content-Disposition: attachment; filename=test.csv'); 74 75 readfile($filepath); 76 77 return response()->download('test.csv'); 78 79 } 80 81 82 //「新規登録」ボタンが押されたとき 83 public function form($request) 84 { 85 return redirect('form'); 86 }
Laravelのルート情報
//最初に表示されるリストページ
Route::get('list', 'MeishiController@list');
//listページにて各ボタンが押されpostが送信された場合
Route::post('list', 'MeishiController@postlist');
試したこと
var_dumpを使い、postが飛んでいるのかを確認しました。post自体は送信されています。
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。