我有两个单独的控制器,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);
}
}
慕容3067478