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', '[email protected]');

2 Answers

1
Matius Nugroho Aryanto On

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

-1
iscpreee On

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>