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 controller create
method on the controller store
method on the controller show
method on the controller edit
method on the controller update
method on the controller destroy
method on the controller Saying 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.