在 Laravel 中使用 id 重定向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45189874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Redirect with id in Laravel
提问by decodedxclusive
Trying to Redirect to a route:
尝试重定向到路由:
return Redirect::route('job_view', array('id' =>$id))
->with('succes','Alread Apply for this post');
Error :InvalidArgumentException in UrlGenerator.php line 314 Route [job_view] not defined.
错误 :InvalidArgumentException 在 UrlGenerator.php 第 314 行 Route [job_view] 未定义。
The route Define in Web.php
Web.php 中定义的路由
Route::get('/job_view/{id}','jobseekerController@job_view');
回答by Bilal Ahmed
you can pass parameter and some status like this
你可以像这样传递参数和一些状态
return Redirect::to('job_view')
->with(['id'=>$id,'succes' => 'Alread Apply for this post']);
['id'=>$id,'succes' => 'Alread Apply for this post']
thats mean you pass two parameters first id
and second is succes
and then you get in view like this
['id'=>$id,'succes' => 'Alread Apply for this post']
这意味着你首先传递两个参数id
,第二个是succes
,然后你会像这样看到
for id: {{$id}}
身: {{$id}}
for succes: {{$succes}}
为了成功: {{$succes}}
回答by Rizwan Shamsher Kaim Khani
You need to define your route in your web.php file like that.
你需要在你的 web.php 文件中定义你的路由。
Route::get('/job_view/{id}', ['as' => 'job_view', 'uses' => 'jobseekerController@job_view']);
回答by decodedxclusive
In your web definition you defined Id but when you were calling the redirect to the job_view, you did not add the id to it. Do this instead
在您的 Web 定义中,您定义了 Id,但是当您调用重定向到 job_view 时,您没有将 id 添加到其中。改为这样做
return redirect()->to('job_view/'.$id);
回答by Alexey Mezenin
Since you use route()
method, you need to define route name:
由于您使用route()
方法,您需要定义路由名称:
Route::get('/job_view/{id}', 'jobseekerController@job_view')->name('job_view');
Or:
或者:
Route::get('/job_view/{id}', ['as' => 'job_view', 'uses' => 'jobseekerController@job_view']);