Laravel 中的 LIKE 查询未收到结果、输出或任何错误

Not receiving results, outputs or any errors with LIKE query in Laravel

我正在尝试使用 Laravel 进行 LIKE 查询,但在返回视图时似乎没有输出任何结果(或错误),有人可以提供帮助吗?视图仅 returns 带有搜索字段(表单)。如有任何帮助或建议,我们将不胜感激。

控制器

public function search()
{
    $input = Request::get('name');
    $properties = Property::where('title', 'like', '%' . $input . '%');

    return view('index', ['properties' => $properties]);
}

查看

@foreach($properties as $property)
    <tr class="item{{$property->id}}">
        <td>{{$property->title}}</td>
    </tr>
@endforeach

您的 $properties = Property::where('title','like','%'.$input.'%'); 只是在查询中添加了 where 子句,没有获取任何数据。替换为

$properties = Property::where('title','like','%'.$input.'%')->get();

到return查询的结果。 (已将 ->get() 添加到查询中)

https://laravel.com/docs/7.x/queries#where-clauses