我有两个单独的控制器,PostController用于将输入值返回给刀片并将APIController数据从数据库返回到刀片。我试过传递变量,SESSION但仍然没有功能。请帮忙。索引.blade.php<form class="form-inline" action="{{ action('PostController@index') }}" method="GET"> <div class="form-group"> <label class="mb-2 mr-sm-2 col-form-label">Date : </label> <input type="date" name="date" id="date" style="width:160px;" class="form-control mb-2 mr-sm-2" value="<?php if(isset($_GET['submit'])) echo $_GET['date']; else echo date('Y-m-d');?>"> </div> <input type="submit" name="submit" class="btn btn-primary mb-2" value="Inquiry"></form>后控制器.php<?php namespace App\Http\Controllers; use Illuminate\Support\Facades\Input; use Session; class PostController extends Controller { public function index() { $getDate = Input::get('date'); //trying to pass this to APIController for query $getCurrentDate = date('Y-m-d'); Session::put('getDate', $getDate); //for example $getDate = '2019-01-01' return view('posts.index')->with('getCurrentDate', $getCurrentDate)->with('getDate', $getDate); } }接口控制器.php<?php namespace App\Http\Controllers; use Illuminate\Support\Facades\DB; use Yajra\Datatables\Datatables; use Session; class APIController extends Controller { public function getQueries() { ini_set('memory_limit', '1024M'); ini_set('max_execution_time', 300); $getInputDate = Session::get('getDate'); //don't get anything here //dd($getInputDate); //have tried dumping, it returns null $getCurrentDate = date('Y-m-d'); if($getInputDate == NULL) { $query = DB::select(DB::raw("SELECT * FROM TABLE WHERE date = '$getCurrentDate'"); return Datatables::of($query)->make(true); } else { $query = DB::select(DB::raw("SELECT * FROM TABLE WHERE date = '$getInputDate'"); return Datatables::of($query)->make(true); } }
2 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
尝试将受影响的路由放在 Web 中间件组中,这样您就应该在它们之间共享会话。
Route::group(['middleware' => 'web'], function () {
// Put routes in here
});
如果我没记错的话,这种情况应该是针对 api 路由的,它希望与 web 路由共享会话。
- 2 回答
- 0 关注
- 137 浏览
添加回答
举报
0/150
提交
取消