laravel NotFoundHttpException

前端 未结 1 1442
天命终不由人
天命终不由人 2021-01-11 12:09

I am new at laravel. I am trying to make a link to another page. I have the page index and want to go to desc which display information about a vehicle selected in index pag

相关标签:
1条回答
  • 2021-01-11 12:45

    The 'NotFoundHttpException' means Laravel wasn't able to find a route to for the request.

    Your desc route is a POST route, only, and a link_to_action will create a GET request, so you may need to change add a GET route too:

    Route::post('desc', array('uses' => 'CarController@show'));
    Route::get('desc', array('uses' => 'CarController@show'));
    

    There's also a any, which does GET, POST, PUT, DELETE:

    Route::any('desc', array('uses' => 'CarController@show'));
    

    If you need to get and id from your route, you will have to add it as a parameter:

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

    And you will have to access your page as:

    http://myappt.al/public/car/22
    

    But if you want to access it as:

    http://myappt.al/public/22
    

    You'll need to do:

    Route::post('{id}', array('uses' => 'CarController@show'));
    

    But this one is dangerous, because it will may grab all the routes, so you MUST to set it as your very last route.

    And your controller must accept that parameter:

    class CarController extends Controller {
    
       public function show($id)
       {
          dd("I received an ID of $id");
       }
    }
    

    EDIT:

    Since you most of your routes made manually, you can also go with the index this way:

    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'));
    
    0 讨论(0)
提交回复
热议问题