Reputation: 670
I'm trying to add methods to my resource routes that have a parameter. If I create one without a parameter it works find, but when I try to add a parameter it doesn't work.
Here's the code
Route::get('temp_user/activate/{id}', 'TempUserController@activate');
Route::resource('temp_user','TempUserController', array('only' => array('index','create','store')));
The above code doesn't work, but I need to pass a parameter to my method. Please help.
Upvotes: 2
Views: 4524
Reputation: 87719
Works fine here. To not create a new controller I just used and old one:
<?php
class StoreController extends Controller {
public function activate($id)
{
return 'activate '.$id;
}
public function index()
{
return 'index';
}
public function create()
{
return 'create';
}
}
Using routes:
Route::get('temp_user/activate/{id}', 'StoreController@activate');
Route::resource('temp_user','StoreController', array('only' => array('index','create','store')));
After executing
php artisan routes
I get
| | GET /temp_user/activate/{id} | | StoreController@activate | | |
| | GET /temp_user | temp_user.index | StoreController@index | | |
| | GET /temp_user/create | temp_user.create | StoreController@create | | |
| | POST /temp_user | temp_user.store | StoreController@store | | |
And browsing:
http://172.17.0.2/temp_user/create
http://172.17.0.2/temp_user/activate/1
http://172.17.0.2/temp_user
Everything works fine.
Upvotes: 4