我一直試圖在laravel的雄辯中創建我自己的可鏈接方法,但我錯過了一些東西,不知道是什麼。這可能聽起來有點瘋狂,但看看我的功能,以更好地瞭解我想說什麼。在laravel中創建一個可鏈接的方法
class Post extends Eloquent{
public static function custom_wh($data){
return static::where_in('categories_id', $data, 'AND');
}
}
//this works fine
$posts = Post::custom_wh(array(1, 2, 3))->get();
//but this says custom_wh is not defined in the query class
$posts = Post::where_in('tags', array(2, 3, 4), 'AND')->custom_wh(array(1, 2, 3))->get();
如果我理解正確,那麼我的方法沒有資格鏈接另一種方法?所以我想我的問題是我如何在我的模型中創建一個可鏈接的方法?
PS我已經看了一下laravel的查詢生成器類,在那裏我已經看到,可鏈式方法返回該對象的實例,但我找不到方法來返回對象,而不是我在上面的代碼。任何形式的建議或建議都非常感謝。提前致謝。
喜歡這個功能,並且已經在使用它了:D我知道這個在我發佈我的問題時並不存在,但我選擇這個作爲像我這樣的其他Google搜索的正確答案。謝謝。 – 2014-01-14 13:50:26