I have a model named PriceList
and when I use the ::resource
function of the Routing, it only works if I pass price/lists
as the first parameter.
For example, if I do the following:
Route::resource('pricelists', 'PriceListsController');
Then inside my controller, I do the following:
use App\PriceList;
class PriceListsController
{
public function show(PriceList $list)
{
dd($list);
}
}
If I visit the url: /pricelists/1
, it's giving me an empty instance of PriceList
:
PriceList {#802 ▼
#appends: array:4 [▶]
#hidden: array:4 [▶]
#with: array:1 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#withCount: []
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: []
#original: []
#changes: []
#casts: []
#dates: []
#dateFormat: null
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
However, if I change the resource to:
Route::resource('price/lists', 'PriceListsController');
And visit the url: /price/lists/1
, I then get the right instance of PriceList
:
PriceList {#820 ▼
#appends: array:4 [▶]
#hidden: array:4 [▶]
#with: array:1 [▶]
#connection: "mysql"
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▶]
#original: array:7 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶]
#touches: []
+timestamps: true
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
How can I change it from price/lists
to pricelists
?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HNLKWK
via IFTTT
Aucun commentaire:
Enregistrer un commentaire