【发布时间】:2019-01-18 19:31:42
【问题描述】:
所以基本上我正在为大学做一个项目,我的项目中唯一缺少的是一个有效的搜索表单,但我不知道该怎么做。我的所有产品都已创建并播种到数据库中。
我的路线:
Route::get('/', [
'uses' => 'ProductsController@getIndex',
'as'=> 'product.index'
] //tenho de meter um . porque nao é uma diretoria global, index ta dentro
duma pasta shop
);
我的桌子:
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string("imagePath");
$table->string("title");
$table->text("description");
$table->integer("price");
});
我的表单结构:
<form action="" method="post" class="navbar-form navbar-left " role = "search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Search</button>
</form>
我的产品管理员:
public function getIndex(){
$products = Products::all();
return view('shop.index', ['products' => $products]);
}
我看过很多关于如何做的教程,但我似乎无法让它过滤我拥有的那些,例如,如果我在商店里有 3 只靴子和 5 只鞋子,如果我写“boot”在搜索中,我只希望出现 3 个靴子
【问题讨论】:
-
你有没有创建搜索路径
-
是的,我做到了,Route::post('/', [ 'uses' => 'ProductsController@searchProducts', 'as'=>'product.search' ]);