I'm quite new to laravel4 but with some codeigniter background. I try to figure out how do I route with url to a controller method
my url should look like
/admin/products{controller_name}/parser{controller_method}
than controller
<?php namespace App\Controllers\Admin;
use App\Models\Product;
use Image, Input, Notification, Redirect, Sentry, Str;
class ProductsController extends \BaseController {
public function index()
{
return \View::make('admin.products.index');
}
public function parser()
{
return \View::make('admin.products.parser');
}
}
Route::group(array('prefix' => 'admin', 'before' => 'auth.admin'), function()
{
Route::resource('products', 'App\Controllers\Admin\ProductsController');
Route::resource('products/parser', 'App\Controllers\Admin\ProductsController@parser');
});
When you use the Route::resource method, you're actually creating many different routes in a single call:
index method on the controllercreate method on the controllerstore method on the controllershow method on the controlleredit method on the controllerupdate method on the controllerdestroy method on the controllerSaying Route::resource('resource', 'Controller') is all that you would need to do in order to create 7 different routes, and is a convenience method really helpful when creating API's.
All that said, I don't think this is what you want to do. Instead, I think you just want to use the regular get and/or post methods for this:
// Here is a single GET route
Route::get('products', 'App\Controllers\Admin\ProductsController@index');
// Here is a single POST route
Route::post('products/parser', 'App\Controllers\Admin\ProductsController@parser');
See more info on Laravel's Resource Controllers in the docs.
As a side note, you can see all of the routes your application is currently aware of by using Artisan's routes command:
$ php artisan routes
You can verify a route is setup correctly by running that command and looking for what method on what controller a given route is being mapped to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With