Exacly what you said...
Route::get('/test/{squirrel}', ['uses' =>'SomeController@doSomething']);
SomeController:
public function doSomething($squirrel)
{
$data['squirrel'] = $squirrel;
return View::make('simple', $data);
}
Works, great! :)
Is there a difference between
Route::get('/test/{squirrel}', ['uses' =>'SomeController@doSomething']);
and
Route::get('/test/{squirrel}', 'SomeController@doSomething');
?
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
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?
Assuming you use Laravel 5
Route::post('employees/{id}', [
'as' => 'employees', 'uses' => 'mot@getemployee'
]);
will do.
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?
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?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community