【问题标题】:Why does echo display the view and the return statement doesn't display anything为什么echo显示视图而return语句什么都不显示
【发布时间】:2015-06-02 03:56:55
【问题描述】:

这是我的createstore 函数:

public function create(Request $request)
{
    $data = $request->except('_token');
    $validator = $this->validator($data);

    if ($validator->fails())
    {
        $this->throwValidationException(
            $request, $validator
        );
    }
    $this->store($data);
    $request->find($request);
    return redirect()->back()->with('message', 'Permintaan berhasil diinput');
}

public function store(array $data){
    Permintaan::create([
        'kdInventaris' => $data['kodeInventaris'],
        'namaInventaris' => $data['namaInventaris'],
        'jenis' => $data['optInventaris'],
        'jumlah' => $data['jumlah'],
        'spesifikasi' => $data['spesifikasi'],
        'keterangan' => $data['keterangan'],
    ]);
}

重定向时,它可以工作,但又得到一个空白页面,并被替换为 echo。

它有效,但有此消息并成功重定向:

“HTTP/1.0 302 找到缓存控制:无缓存日期:周一,2015 年 6 月 1 日 格林威治标准时间 16:04:33 位置:http://localhost:8000/permintaan 重定向到 http://localhost:8000/permintaan。”

我想知道这个错误是否与我的return redirect()->back()->with('message', 'Permintaan berhasil diinput');有关。

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    redirect() 表示您正在尝试返回命名路由

    如果你确实使用redirect(),那么你应该给出一个命名路由,例如return redirect()->route('someroute');

    您不能将它用于back。但是,如果你想这样做,那么你可以简单地通过

    重定向回来
    Redirect::back()->withMessage('Permintaan berhasil diinput')
    

    甚至你可以使用

    return redirect()->back()->with('message', 'Permintaan berhasil diinput');
    

    您可以在此处了解更多关于 Laravel's Documentation 重定向的信息

    【讨论】:

    • 哇。你是我的英雄。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多