2017-06-17 86 views
0

這是我的路線:沒有定義路由

$app->group(['prefix' => 'book/'], function ($app) { 
    $app->get('/','[email protected]'); //get all the routes  
    $app->post('/','[email protected]'); //store single route 
    $app->get('/{id}/', '[email protected]'); //get single route 
    $app->put('/{id}/','[email protected]'); //update single route 
    $app->delete('/{id}/','[email protected]'); //delete single route 
}); 

當我嘗試生成一個URL,這個Route沒有定義[圖書]系統返回。

@foreach ($books as $book) 
    <li> 
     <a href="{{ route('book', ['id' => $book->id]) }}"> 
      {{ $book->name}} 
     </a> 
    </li> 
@endforeach 

我錯過了什麼?

+0

我可能是由於雙斜槓書/ +'/',因此您的路線似乎不正確的一般病後我將如何寫路線給我一個分鐘 – utdev

+0

@utdev我嘗試刪除第二個'/',但沒有任何反應。等待你的解決方案。 – marcelo2605

回答

1

嘗試這種方式,因此它更易讀:

# Book routes 
Route::group(['prefix' => 'books'], function() 
{ 
    Route::get('/', ['as' => 'index', 'uses' => '[email protected]']); 
    Route::post('store', ['as' => 'store', 'uses' => '[email protected]']); 
    Route::get('show/{id}', ['as' => 'show', 'uses' => '[email protected]']); 
    Route::post('update/{id}', ['as' => 'update', 'uses' => '[email protected]']); 
    Route::delete('destroy/{id}', ['as' => 'destroy', 'uses' => '[email protected]']); 
}); 

我也認爲你不需要put方法,你可以使用update + method spoofing在你的窗體中。有關方法欺騙的更多信息,請查看docs

2

你沒有名字的路線

$app->group(['prefix' => 'book/'], function ($app) { 

    $app->get('/{id}/', [ 
     'as' => 'book', 
     'uses' => '[email protected]' 
    ]); 

}); 

然後你就可以做到這一點

@foreach ($books as $book) 
<li> 
    <a href="{{ route('book', ['id' => $book->id]) }}"> 
     {{ $book->name}} 
    </a> 
</li> 
@endforeach