---
# System prepended metadata

title: Laravel7 Route pattern cannot reference variable name more than once
tags: [PHP, ' Backend', ' Laravel']

---

---
tags: PHP, Backend, Laravel
---

# Laravel7 Route pattern cannot reference variable name more than once

在路由設置為以下時發生錯誤:

`Route::resource('/temporary/{store_id}', 'Store\TemporaryTimeController');`

錯誤訊息如下:

`Route pattern "/temporary/{store_id}/{{store_id}}" cannot reference variable name "store_id" more than once.`

應該是resource 會自動將 route 最後的那個單詞作為變量，所以出現了報錯日誌中的變量名重複的問題。

解決辦法:
路由不以變量為結尾，多加上文字
Route::resource('/temporary/{store_id}', 'Store\TemporaryTimeController');