Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0

Exacly what you said...

Route::get('/test/{squirrel}', ['uses' =>'SomeController@doSomething']);

SomeController:

public function doSomething($squirrel)
{
  $data['squirrel'] = $squirrel;
  return View::make('simple', $data);
}
Last updated 2 years ago.
0

Works, great! :)

Is there a difference between

Route::get('/test/{squirrel}', ['uses' =>'SomeController@doSomething']);

and

Route::get('/test/{squirrel}', 'SomeController@doSomething');

?

Last updated 2 years ago.
0

Well It works both times (which I did not know it will :D)
But it is a good practice to name the route so you can reference it by name.

Route::get('/test/{squirrel}', ['uses' =>'SomeController@doSomething', 'as'=>'routeName']);

In this case you have to use array and keys 'uses' and 'as'. Other then that I believe there is no difference

You can read about this topic here
http://laravel.com/docs/routing#named-routes

Last updated 2 years ago.
0

how about if post and not get? like

Route::post('employees',[
    'as' => 'employees/', 'uses' => 'mot@getemployee'
]);

How im going to pass the data key named "id" to a controller that will be used as its argument?

0

Assuming you use Laravel 5

Route::post('employees/{id}', [
    'as' => 'employees', 'uses' => 'mot@getemployee'
]);

will do.

0

I use like this in my route.php:

Route::get('/books/{id}', ['uses' =>'BookController@show']);

But i am error:

NotFoundHttpException in RouteCollection.php line 145:

what i did wrong with above route coding?

0

I think you should leave out the first / in your route

instead of Route::get('/books/{id}',

try Route::get('books/{id}',

kailashkumar075 said:

I use like this in my route.php:

Route::get('/books/{id}', ['uses' =>'BookController@show']);

But i am error:

NotFoundHttpException in RouteCollection.php line 145:

what i did wrong with above route coding?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Sharping sharping Joined 28 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.