laravel NotFoundHttpException

10 php laravel-4

我是laravel的新人.我正在尝试建立到另一个页面的链接.我有页面索引,并且想要显示关于在索引页面中选择的车辆的信息的desc.问题是它显示错误:

Symfony\Component\HttpKernel\Exception\NotFoundHttpException

index.blade.php

    @foreach ($cars as $car)
           <tr>                                   
           <td> 
           {{link_to_action('CarController@show',  $car->Description, $car->id)}}</td>  
             {{ Form::open(array('action' => 'CarController@show', $car->id)) }}
                  {{ Form::close() }}
                        <td>{{ $car->License }}</td>  
                        <td>{{ $car->Milage }}</td> 
                        <td>{{ $car->Make }}</td>  
                        <td>{{ $car->status }}</td>                                    
          </tr>                                                            
    @endforeach
Run Code Online (Sandbox Code Playgroud)

routes.php文件

Route::resource('/', 'CarController');
Route::resource('create', 'DataController');
Route::post('desc', array('uses' => 'CarController@show'));
Route::post('create', array('uses' => 'CarController@create', 'uses' => 'DataController@index'));
Route::post('update', array('uses' => 'CarController@update'));
Route::post('store', array('store' => 'CarController@store'));
Run Code Online (Sandbox Code Playgroud)

Ant*_*iro 13

'NotFoundHttpException'表示Laravel无法找到请求的路由.

您的desc路由只是一个POST路由,并且link_to_action会创建一个GET请求,因此您可能还需要更改添加GET路由:

Route::post('desc', array('uses' => 'CarController@show'));
Route::get('desc', array('uses' => 'CarController@show'));
Run Code Online (Sandbox Code Playgroud)

还有一个any,它可以执行GET,POST,PUT,DELETE:

Route::any('desc', array('uses' => 'CarController@show'));
Run Code Online (Sandbox Code Playgroud)

如果您需要id离开路线,则必须将其添加为参数:

Route::post('car/{id}', array('uses' => 'CarController@show'));
Run Code Online (Sandbox Code Playgroud)

您必须访问您的页面:

http://myappt.al/public/car/22
Run Code Online (Sandbox Code Playgroud)

但是如果你想访问它:

http://myappt.al/public/22
Run Code Online (Sandbox Code Playgroud)

你需要这样做:

Route::post('{id}', array('uses' => 'CarController@show'));
Run Code Online (Sandbox Code Playgroud)

但是这个很危险,因为它可能会抓住所有路线,所以你必须把它设置为你最后的路线.

并且您的控制器必须接受该参数:

class CarController extends Controller {

   public function show($id)
   {
      dd("I received an ID of $id");
   }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

由于您手动制作了大多数路线,因此您也可以这样使用索引:

Route::resource('create', 'DataController'); 

Route::get('/', 'CarController@index');

Route::post('create', array('uses' => 'CarController@create','uses' => 'DataController@index')); 
Route::post('update', array('uses' => 'CarController@update')); 
Route::post('store', array('store' => 'CarController@store')); 

Route::get('{id}', array('uses' => 'CarController@show'));
Route::post('{id}', array('uses' => 'CarController@show'));
Run Code Online (Sandbox Code Playgroud)