如何使用Laravel将数据从一个页面发送到另一个页面?

如何使用Laravel将数据从一个页面发送到另一个页面?

问题描述:

So I'm using laravel 5.1 and I'm stuck in a weird situation.

I have 2 models Seasonand Tournament and lets say the url to add a Season model is ..../seasons/add and to view the season would be ..../seasons/(id)... standard stuff right?

But now I want to add a tournament from the link ..../seasons/1 and so I click a link that takes me to ..../tournaments/add... how can I send the Season model to that page without submitting a form with hidden input?

Currently I have this setup ..../seasons/1/tournaments/add using blade to generate the links. But this method just doesn't feel right....

Thanks.

所以我正在使用laravel 5.1而且我陷入了一种奇怪的境地。 p>

我有2个模型 Season code>和 Tournament code>,让我们说添加 Season code>模型的url是 .... / seasons / add code>并查看本季将是 .... / seasons /(id) code> ...标准的东西吧? p>

但现在我想从链接 .... / seasons / 1 code>添加锦标赛,所以我点击一个链接,带我去 .... / tournaments / add code> ...如何在不提交带有隐藏输入的表单的情况下将 Season code>模型发送到该页面? p>

目前我使用刀片设置 .... / seasons / 1 / tournaments / add code>来生成链接。 但是这种方法感觉不对.... p>

谢谢。 p> div>

How can I send data from one page to another using Laravel?: I would suggest that you do this from your controller. Take a look at Redirecting With Flashed Session Data, it might come in handy.

From the Flash Data documentation: "[...] it will only be available during the subsequent HTTP request, and then will be deleted [...]"

You can send your model, static values or whatever you want using ->with:

redirect('route')->with('key', 'value');