我想将数据从一个视图发送到另一个Laravel视图 [英] i want to send data from one view to another Laravel view
本文介绍了我想将数据从一个视图发送到另一个Laravel视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个视图,即view-1和view-2.
i have two views, view-1 and view-2.
- view-1 具有表单,该表单将临时存储数据. 我想从 view-1 获取数据并将其发送到具有用户个人资料的 view-2 ,其中临时数据来自 view-1 将显示.
- 我们如何在Laravel中实现它,我知道我们可以在SQL中存储数据 然后获取它,但是如何在不存储到SQL的情况下做到这一点.
- 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.
我的代码: 查看: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>
视图2控制器:
public function report2($id)
{
$teacher = Teacher::teacher($id);
return View('teachers.report2' ,compact('teacher','today','sdate'));
}
路线:
Route::get('teachers/{id}/report2', 'TeachersController@report2');
推荐答案
使用会话,例如在view1中,您传递date变量在视图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');
进一步阅读,请参见文档
这篇关于我想将数据从一个视图发送到另一个Laravel视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文