1

I am using CodeIgniter from 2 years and i am trying to move to Laravel and I saw many tutorials of how to use Laravel but i couldn't find any answers to how to pass variables to functions using the URL and without using routes like in CodeIgniter if i called this link site.com/users/edit/12.

I would be calling the users controller , the edit function and passing a variable of value 12 how can i do the same in Laravel without using routes for every single function or using query strings which will make the URL ugly?

The Alpha
  • 143,660
  • 29
  • 287
  • 307
Joseph Girgis
  • 3,115
  • 4
  • 19
  • 20

2 Answers2

1

Here is an example.Hope that it will be helpful.......

route.php

Route::controller('users','UsersController');

UsersController.php

class UsersController extends BaseController
{       

    public function getEdit($value)
    {
        echo $value;
    }
}

url

site.com/users/edit/12

output

12
Tanvir
  • 1,635
  • 2
  • 17
  • 31
0

In Laravel - 3 you may do it using something like this:

Route::controller(Controller::detect());

But in later versions it's not available and you should explicitly declare the routes. Actually it's better to declare routes explicitly and this approach has many benefits too. This is a common problem that happens to developers who migrates from CodeIgniter but later they get motivated and if you use this you'll love this for sure.

You may read this article by Phil Sturgeon who was the man behind the CodeIgniter framework, he discussed about it's down sides of this (automatic routing).

If you are using Laravel - 4 then check the Controllers Manual, specially check out the RESTful and Resourceful controllers section, it may attract you but be familiar with explicit route declaration first.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
  • The thing is i am trying to migrate a full e-commerce system that was originally built in codeigniter. if i remember correctly there was a controller with more than 200 functions it would be a tedious work to define a route for each one of them. there is no way to automate that without having to write a route for each function ? – Joseph Girgis Jun 07 '14 at 00:58
  • There is no way in `L-4` but like i said; you may use `RESTful/Resourceful` controllers. – The Alpha Jun 07 '14 at 01:01