Pet*_*ete 1 php laravel eloquent
这是一个例子,在Laravel中使用Eloquent.
假设我正在使用CMS.
示例控制器代码:
Route::get('(.*)', function($route)
{
$page = Page::load_by_route($route);
});
Run Code Online (Sandbox Code Playgroud)
示例代码:
class Page extends Eloquent {
public static function load_by_route($route)
{
// Explode the route and trace to find the actual id of the row we need.
// ... some lines of code to accomplish it...
// Use the $id we discovered to perform the actual query
$page = Page::find($id)->first();
return $page;
}
}
Run Code Online (Sandbox Code Playgroud)
在你问"为什么你不能只使用Page :: where('route','=',$ route) - > first()之前:我不想知道'怎么做'这个例子.我只是想知道在页面模型中使用Page ::是否不好?
| 归档时间: |
|
| 查看次数: |
1917 次 |
| 最近记录: |