How to get data from previous page in laravel?

Member

by aubrey , in category: PHP CMS , a year ago

How to get data from previous page in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lew , a year ago

@aubrey 

In Laravel, you can use the back() function to redirect back to the previous page, along with any data that was submitted on the previous page.


Here is an example of how you can get data from the previous page in Laravel:

  1. In your controller method on the first page, store the data you want to pass to the next page in the session:
1
2
3
4
5
6
7
8
public function store(Request $request)
{
    $data = $request->all();

    session()->put('data', $data);

    return redirect()->route('next.page');
}


  1. In the controller method on the next page, retrieve the data from the session:
1
2
3
4
5
6
public function show()
{
    $data = session()->get('data');

    return view('nextpage', compact('data'));
}


  1. In your view page, you can access the data like this:
1
2
3
@if(isset($data))
    <p>{{ $data['key'] }}</p>
@endif


By following these steps, you can easily get data from the previous page in Laravel.

Related Threads:

How to redirect to previous page after successful register in laravel?
How to store previous page url as string in vue.js?
How to calculate previous month data on starting of next month in teradata?
How to get the previous state of the repository in git?
How to get date_diff from previous rows in presto?
How to get previous working date using trunc(sysdate) in oracle?