Passing parameter to controller from route in laravel

前端 未结 4 1854
孤城傲影
孤城傲影 2020-12-16 09:15

THIS IS A QUESTION FOR LARAVEL 3

Given the following route

Route::get(\'groups/(:any)\', array(\'as\' => \'group\', \'uses\' =>         


        
相关标签:
4条回答
  • 2020-12-16 09:49
        $ php artisan route:list
      +--------+--------------------------------+----------------------------+--    -----------------+----------------------------------------------------+---------  ---+
      | Domain | Method                         | URI                        |  Name              | Action                                             |    Middleware |
      +--------+--------------------------------+----------------------------+-------------------+----------------------------------------------------+------------+
      |        | GET|HEAD                       | /                          |                           
      |        | GET                            | campaign/showtakeup/{id}   | showtakeup         | App\Http\Controllers\campaignController@showtakeup | auth       |     |
    

    routes.php

      Route::get('campaign/showtakeup/{id}', ['uses' =>'campaignController@showtakeup'])->name('showtakeup');
    

    campaign.showtakeup.blade.php

     @foreach($campaign as $campaigns)
    
    
       //route parameters; you may pass them as the second argument to the method:
    
       <a href="{{route('showtakeup', ['id' => $campaigns->id])}}">{{ $campaigns->name }}</a>
    
    
    
    
                @endforeach
    

    Hope this solves your problem. Thanks

    0 讨论(0)
  • 2020-12-16 10:01

    This is what you need in 1 line of code.

    Route::get('/groups/{groupId}', 'GroupsController@getShow');

    Suggestion: Use CamelCase as opposed to underscores, try & follow PSR-* guidelines.

    Hope it helps.

    0 讨论(0)
  • 2020-12-16 10:03

    You can add them like this

      Route::get('company/{name}', 'PublicareaController@companydetails');
    
    0 讨论(0)
  • 2020-12-16 10:04

    You don't need anything special for adding paramaters. Just like you had it.

    Route::get('groups/(:any)', array('as' => 'group', 'uses' => 'groups@show'));
    
    
    class Groups_Controller extends Base_Controller {
    
        public $restful = true;    
    
        public function get_show($groupID) {
            return 'I am group id ' . $groupID;
        }  
    
    
    }
    
    0 讨论(0)
提交回复
热议问题