【问题标题】:Redirect with id in Laravel在 Laravel 中使用 id 重定向
【发布时间】:2017-12-24 16:26:05
【问题描述】:

尝试重定向到路由:

return Redirect::route('job_view', array('id' =>$id))
                ->with('succes','Alread Apply for this post');

错误:UrlGenerator.php 第 314 行中的 InvalidArgumentException 路线 [job_view] 未定义。

路由定义在Web.php

Route::get('/job_view/{id}','jobseekerController@job_view');

【问题讨论】:

  • 如何在web.php中定义job_view路由,可以在这里给出
  • Route::get('/job_view/{id}','jobseekerController@job_view');
  • 这样做Route::get('/job_view/{id}','jobseekerController@job_view')->name('job_view');

标签: php laravel


【解决方案1】:

在您的 Web 定义中,您定义了 Id,但是当您调用重定向到 job_view 时,您没有向其中添加 id。改为这样做

return redirect()->to('job_view/'.$id);

【讨论】:

    【解决方案2】:

    你可以像这样传递参数和一些状态

    return Redirect::to('job_view')
    ->with(['id'=>$id,'succes' => 'Alread Apply for this post']);
    

    ['id'=>$id,'succes' => 'Alread Apply for this post'] 这意味着您首先传递两个参数id,第二个是succes,然后您会像这样进入视图

    对于 id:{{$id}}

    成功:{{$succes}}

    【讨论】:

    • 需要用 Id 重定向但 id 重定向像这样127.0.0.1:8000/job_view
    • 我提到了'id'=>$id
    • 我已经用更多细节更新了我的答案。我认为这个细节会对你有所帮助
    【解决方案3】:

    你需要像这样在 web.php 文件中定义你的路由。

    Route::get('/job_view/{id}', ['as' => 'job_view', 'uses' => 'jobseekerController@job_view']);
    

    【讨论】:

      【解决方案4】:

      由于你使用route()方法,你需要定义路由名称:

      Route::get('/job_view/{id}', 'jobseekerController@job_view')->name('job_view');
      

      或者:

      Route::get('/job_view/{id}', ['as' => 'job_view', 'uses' => 'jobseekerController@job_view']);
      

      【讨论】:

        猜你喜欢
        • 2019-01-26
        • 2021-04-05
        • 1970-01-01
        • 1970-01-01
        • 2018-04-08
        • 1970-01-01
        • 2021-12-02
        • 2016-02-25
        • 2019-02-12
        相关资源
        最近更新 更多