laravel 5.5中路由的自定义名称

时间:2017-10-09 21:26:59

标签: laravel laravel-5 laravel-routing laravel-5.5

我使用这些路线

Route::namespace('Panel\Admin')->prefix('admin')->group(function (){
  $this->get('/', 'HomeController@index');

  $this->namespace('Users')->prefix('users')->group(function (){

    $this->get('/' , 'UserController@index')->name('users');
    $this->delete('/{user}/destroy' , 'UserController@destroy')->name('users.destroy');
    $this->get('/create' , 'UserController@create')->name('users.create');
    $this->post('/store' , 'UserController@store')->name('users.store');
    $this->get('/{user}/edit' , 'UserController@edit')->name('users.edit');
    $this->patch('/{user}/update' , 'UserController@update')->name('users.update');

它有效。

例如php artisan route:list我有这些:

admin/users                               | users 
admin/users/create                        | users.create 
admin/users/store                         | users.store 
admin/users/{user}/destroy                | users.destroy

但我想写代码简短:

Route::namespace('Panel\Admin')->prefix('admin')->group(function (){
  $this->get('/', 'HomeController@index');

  $this->namespace('Users')->prefix('users')->group(function (){

    $this->resource('/' , 'UserController');
    $this->resource('/test' , 'UserController');

php artisan route:list我有这些:

admin/users                               | index 
admin/users                               | store 
admin/users/create                        | create 
admin/users/{}                            | show 
admin/users/{}                            | update 
admin/users/{}                            | destroy  
admin/users/{}/edit                       | edit 

这是错的。但是测试是正确的。例如:

admin/users/test                          | test.store 
admin/users/test/{test}/edit              | test.edit 

我错了什么?

2 个答案:

答案 0 :(得分:0)

user

这将为用户创建所有标准路线。

您不应该包含前缀import threading import time def dicthing(dic, x): dic.update({x: x*x}) time.sleep(0.01) dic = {} threads = [] x = 100 while x > 0: t = threading.Thread(target = dicthing, args = (dic, x)) threads.append(t) t.start() x -= 1 if x % 50 == 0: print(len(threads), len(threading.enumerate())) for t in threads: if t.is_alive() == False: t.join() t.kill = True threads = [t for t in threads if not t.kill] ,因为它会创建前缀。

答案 1 :(得分:0)

resource方法的第一个参数应该是资源的名称, 因此,您应删除users前缀并添加users作为资源的名称

$this->resource('users' , 'UserController');

您可以在documentation

上阅读更多相关信息