小编Saj*_*ood的帖子

如何找到Array的大小

我想知道如何找到数组的大小,以及如何执行数组大小大于零的代码块?

if ($result > 0) {
    // Here is the code body which I want to execute
} 
else {
    // Here is some other code
}
Run Code Online (Sandbox Code Playgroud)

php arrays if-statement counting

26
推荐指数
3
解决办法
5万
查看次数

Laravel 方法 Illuminate\Database\Eloquent\Collection::toSql 不存在。错误

我想从数据库中搜索所有记录,然后过滤这些记录,但是当我想查看查询时

dd($posts->toSql());
Run Code Online (Sandbox Code Playgroud)

它给了我错误

"Illuminate\Database\Eloquent\Collection::toSql does not exist."
Run Code Online (Sandbox Code Playgroud)

它又给了我一个错误

"Method Illuminate\Database\Eloquent\Collection::paginate does not exist."
Run Code Online (Sandbox Code Playgroud)
$posts = Post::all();

        if( !is_null($brand) )
            $posts = $posts->where('brand', $brand);

        if( !is_null($car_type) )
            $posts = $posts->where('car_type', $car_type);

        if( !is_null($color) ){
            $posts = $posts->where('exterior_color', $color);
        }
        $posts = $posts->whereBetween('year',[$from_year,$to_year]);   
        $posts = $posts->whereBetween('milage',[$min_milage,$max_milage]);
        $posts = $posts->whereBetween('price',[$min_price,$max_price]);

        $posts = $posts->paginate(4);

        dd($posts->toSql());

Run Code Online (Sandbox Code Playgroud)

php eloquent laravel-5

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×2

arrays ×1

counting ×1

eloquent ×1

if-statement ×1

laravel-5 ×1