Answer the question
In order to leave comments, you need to log in
Laravel. How to change primaryKey in query to model?
There is a page table
There is a Page class
<?php
class Page extends Eloquent
{
}
Route::model('page', 'Page');
Route::get('/pagebyid/{page}', function(Page $page)
{
print_r($page);
});
Route::model('url', 'Page');
Route::get('/pagebyurl/{url}', function(Page $url)
{
print_r($url);
});
protected $primaryKey = 'url';
Route::get('/pagebyurl/{url}', function($url)
{
$page = Page::where('url', $url)->get();
print_r($page);
});
Answer the question
In order to leave comments, you need to log in
Defining routes with Route::model() is good to use when you have a fully CRUD application. Let's say, if a fairly simple API for something or a resource is sharpened to work with data such as directories. Otherwise, I highly recommend splitting the routes. Since it will always be possible to find the desired route and fix it (debugging / support will not be such a headache), you can always see and manage the types of requests (work on code development will be simplified), and if any changes are made to this method, then do not there will be problems with reworking the code (simplifying and improving compatibility). Plus, if you put the logic in a separate application layer, it will also be easier to develop and maintain...
All this applies to Route::controller().
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question