i want to send data from one view to another Laravel view

三世轮回 提交于 2019-12-11 12:27:44

问题


i have two views, view-1 and view-2.

  • view-1 has form, which will store data temporary.
  • i want to get data from view-1 and send it to view-2, which has user profile, where temporary data from view-1 will be shown.
  • how we can achieve it in Laravel, i know we can store data in SQL and then fetch it, but how to do it without storing to SQL.

my code: view: 1

<form >
  <div class="form-group">
    <label class="col-form-label" >Date</label>
    <input type="text" name="sdate" class="form-control">
    <input type="submit"  class="btn btn-primary" value="Add date" >
  </div>
</form>

view 2 Controller:

public function report2($id)
{
$teacher = Teacher::teacher($id);
return View('teachers.report2' ,compact('teacher','today','sdate'));
}

Route:

Route::get('teachers/{id}/report2', 'TeachersController@report2');

回答1:


Use session, for example in view1 you pass variable of date do this on your controller of view 1

session(['sdate' => $request->sdate]);

and then you can get the value of the session in your controller or view by calling this

$date = session('sdate');

further reading see the docs




回答2:


i was able to do it using simple php; in view 1 i added this code:

<form action="report2"  method="get">
  Date: <input type="text" name="today" placeholder="Date of Birth"  class="datepicker form-control"><br>
  <input type="submit">
</form>

Laravel view 2:

<?php echo $_GET["today"]; ?><br>


来源:https://stackoverflow.com/questions/56108404/i-want-to-send-data-from-one-view-to-another-laravel-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!