post、またはgetにより、変数データ(オブジェクト)をコントローラー部分へ送る方法はありますでしょうか?
具体的には下記コードTestController.phpの「test」メソッド内にて、index.blade.phpへ送った$dateを、index.blade.phpのフォーム内にて組み込み、TestControllerの「index」メソッド内にて、ルーティングを通し渡したいです。
以下は、TestController.phpです。
※ミニマムコードとして、作成しましたので多少省かせてもらっています。
<?php class Testcontroller extends Controller{ public function test(){ $date = new Carbon(); return view('index',['date' => $date]); } public function index(Request $request){ $data = $request->data; } }
以下は、index.blade.phpです
<html> <body> <form method="post" action="/index" > <input type="submit" value='送信'> <input type="hidden" name="data"value="{{$date}}"> </form> </body> </html>
以下は、ルーティング部分のweb.phpです
<?php Route::post('/index','TestController@index'); Route::get('/test','TestController@test') ?>
ご回答頂けましたら、幸いです。
よろしくお願いします。