【发布时间】:2017-03-17 00:56:41
【问题描述】:
我最近一直在学习laravel 5.2,对laravel的工作原理有了基本的了解,我做了一个基本的搜索功能,想从我的数据库中搜索记录
这是我的 ProductenController 中的搜索功能
public function search(request $request)
{
//searching for products by name
Producten::where('naam', 'LIKE', '%$request->naam%');
return redirect(route('producten.index')->with($request));
}
在 producten.index.blade 我有我的搜索
{!! Form::open(['route' => 'producten.index', 'method' => 'GET', 'class' => 'search']) !!}
{!! Form::text('naam')!!}
{!! Form::close() !!}
这也是我的路线
Route::resource('producten', 'ProductenController', ['only' => ['index', 'store', 'delete', 'edit', 'update', 'create', 'search']]);
这是我要从中搜索记录的模型。
class Producten extends Model
{
// model producten holdes the attribues naam, inkoopprijs, verkoopprijs,
protected $fillable = ['Id', 'naam',' inkoopprijs', 'verkoopprijs', 'fabrieken_Id'];
protected $table = 'Producten';
public $timestamps = false;
}
如果有什么我忘了包括让你能够帮助我,请告诉我
【问题讨论】:
-
您能解释一下无法正常工作的确切含义吗?
-
当我搜索产品时,它没有显示我正在搜索的产品
-
它是否显示任何内容?一些错误...或空白页?
-
你的代码完全错误,我不知道从哪里开始。
-
你认为你的查询产品会神奇地去任何地方吗?
标签: php laravel-5.2