gpt4 book ai didi

php - Laravel 5 - withInput 在与重定向一起使用时不起作用

转载 作者:搜寻专家 更新时间:2023-10-31 21:26:05 26 4
gpt4 key购买 nike

我一直在尝试做的是发送一个参数作为输入值并使用 Laravel 5.2 重定向。

我引用了官方文档,Stackoverflow和Laracast上的一些帖子,这里是我的尝试。

//This controller function is run by a POST method and gets an input value
public function makeCustomerId()
{
return redirect('next')
->withInput();
}

下面是我的下一次尝试,基于文档。

(可以通过$this->request->input('id', '')获取输入值)

public function makeCustomerId()
{
return redirect()
->action('PageController@showNextPage', ['inputId' => $this->request->input('id', '')]);
}

我使用 dd() 函数调试 Controller ,但两种情况都没有发送任何内容。

你看到我做错了什么吗?任何建议将不胜感激!

编辑

我添加了更多信息。

上面的 Controller 函数是从以下形式运行的。这最终将导致 PageController@showNextPage

    <form action="{{url('makeCustomerId')}}" method="POST">
<select name="id">
@foreach ($teams as $team)
<option value="{{$team->id}}">{{$team->id}}</option>
@endforeach
</select>
<br>
<input type="submit" value="Submit">
</form>

可能不清楚,但是输入参数($this->request->input('id', ''))对应的是$team->id .

下面是我如何使用$this->request。简而言之,这是依赖注入(inject),这意味着我通过 $this->request

在 Controller 类中的任何位置使用 request
use Illuminate\Http\Request;

class PageController extends Controller {
protected $request;

public function __construct(Request $request)
{
$this->request = $request;
}

}

最佳答案

当你打电话时:

return redirect()
->action('PageController@showNextPage', ['inputId' => $this->request->input('id', '')]);

您实际上所做的是使用 'inputId' 作为输入发出新请求。因此,在您的 showNextPage 方法中,您还需要通过如下方式访问 'inputId':

public function showNextPage()
{
$id = $this->request->input('inputId');

// do stuff
// return next page
}

关于php - Laravel 5 - withInput 在与重定向一起使用时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35902831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com