- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Laravel 初学者,现在尝试在我的网站上构建一个简单的搜索栏。
但我收到此错误:
Class 'products' not found
有人可以告诉我我在 Controller 中忘记了什么吗?
索引搜索表单:
<ul class="searchbar">
<form action="/search" class="light" method="POST" role="search">
{{ csrf_field() }}
<input type="text" class="form-control" name="q" placeholder="Find your item" />
<input type="submit" value="Search" />
</form>
search.blade.php:
@extends('master.main')
@if(Auth::check())
@section('main-content')
@component('master.notification')
@slot('size')
col-md-8 col-md-offset-2
@endslot
@slot('title')
Product Search
@endslot
<div class="container">
@if(isset($products))
<h2>Product Search</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Product</th>
<th>Description</th>
</tr>
</thead>
<tbody>
@foreach($products as $dummy)
<tr>
<td>{{$dummy->name}}</td>
<td>{{$dummy->description}}</td>
</tr>
@endforeach
</tbody>
</table>
{!! $products->render() !!}@endif
</div>
<div class="container">
@if(isset($details))
<p> The Search results for <b> {{ $query }} </b> are :</p>
<h2>Product Search</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Product</th>
<th>Description</th>
</tr>
</thead>
<tbody>
@foreach($details as $products)
<tr>
<td>{{$products->name}}</td>
<td>{{$products->description}}</td>
</tr>
@endforeach
</tbody>
</table>
@if($details){!! $details->render() !!}@endif
@elseif(isset($message))
<p>{{ $message }}</p>
@endif
</div>
@endcomponent
@stop
@endif
web.php:
Route::get ( '/', function () {
$mydatabase = products::paginate(25);
return view ( 'search' )->withproducts($mydatabase);
} );
Route::any ( '/search', function () {
$q = Input::get ( 'q' );
if($q != ""){
$products = products::where ( 'name', 'LIKE', '%' . $q . '%' )->orWhere ( 'description', 'LIKE', '%' . $q . '%' )->paginate (5)->setPath ( '' );
$pagination = $products->appends ( array (
'q' => Input::get ( 'q' )
) );
if (count ( $products ) > 0)
return view ( 'search' )->withDetails ( $products )->withQuery ( $q );
}
return view ( 'search' )->withMessage ( 'No Products found. Try to search again !' );
} );
错误来自:
Route::get ( '/', function () { $mydatabase = products::paginate(25);
products
或 Product::paginate
是如何定义的,或者我必须在 web.php
中使用 ProductController@...
?是的,我发现它不是我的数据库表 products
;)我认为 Product
而不是 products
是正确的,对吗?
/App/Product.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Storage;
class Product extends Model
{
public function category(){
return $this->belongsTo('App\Category');
}
public function seller(){
return $this->belongsTo('App\User');
}
public function buyer(){
return $this->belongsTo('App\User');
}
public function bids(){
return $this->hasMany('App\Bid');
}
public function purchases(){
return $this->hasMany('App\Purchase');
}
}
最佳答案
您必须在 Controller 的开头添加(导入您的类(class)产品)(针对您的情况的 web.php)
use namespace\products
将命名空间替换为您的命名空间(类产品的路径)例如:\app最好使用 Controller ProductController 并重新定义您的功能
关于php - Laravel Searchbar 类 'products' 未找到/ProductController@?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46050547/
我的 SearchFragment 是另外两个 Fragment 的宿主 Fragment:SearchUsersFragment 和 SearchEventsFragment。我的组织方式是 Tab
tableView.tableHeaderView = UISearchDisplayController.searchBar;并调用 setContentInset: ; 当我滚动表格时,没有绘制
我一直在努力寻找答案,但也许我没有正确地询问谷歌,所以它是这样的:我的 Android 应用程序中有一个搜索 View ,其中有顶部菜单项作为搜索输入,等等。我点击放大镜,然后文本字段变为可编辑的搜索
我已经设置了 UISearchBar 的东西。但我收到错误消息。 Cannot assign value of type '[cellData]' to type '[String]' 这是代码 st
我正在疯狂地尝试让我的 IOS 搜索栏在 Iphone 上工作。我从远程服务器访问数据并填充内容文件。然后我做了一个过滤器,它创建了一个过滤后的内容文件。然后我执行 [self.tableView r
我有一个 tableView,其中填充了一个 String 类型的数组。字符串中的某些单词包含连字符 (-)。我知道我可以过滤一个 tableView 并在需要时让它删除这个字符。是否可以在搜索过程中
我有一个带有 SegmentedControl、UITableView 和 UISearchController 的 UIViewController。 SegmentedControl 位于主视图的
当我像这样将 searchBar 对象调用到 UISearchBar 委托(delegate)方法中时,它工作正常: -(void)searchBarSearchButtonClicked:(UISe
我的 SearchBar 有这段代码可以更改我的收藏 View : extension ProductsCollectionViewController : UISearchControllerDel
只是一些后见之明,让您了解我的问题。我目前正在为我在设备上保存了 GuestList CoreData 的事件编写 iOS 应用程序。 在 viewDidLoad 上,它会获取 coredata 对象
我正在按照本教程了解如何启动和运行 searchBar。 教程: https://www.raywenderlich.com/113772/uisearchcontroller-tutorial 我完
我正在尝试对我的应用实现搜索。以前看了好几个教程,都推荐把Search Bar放到Table Header: self.tableView.tableHeaderView = self.searchC
我的搜索栏有默认的灰色文本,但我希望它是白色文本。我无法弄清楚如何使用 swift 来更改范围栏文本颜色,而且您无法从 Storyboard 中执行此操作。我找到的最接近的是 searchBarOut
我刚刚在我的程序中添加了一个 ui 搜索栏,每次我重新运行该程序时,我都会收到错误消息 -[一般] 与守护程序的连接无效尽管如此,我的应用程序仍能完美运行,而且我似乎无法分辨出哪里出了问题。 有谁知道
我又会显得很傻了,但这总比发疯好!这是我的问题。我有一个 UISearchBar,其中有一个我想隐藏的scopeBar。我这样做: searchBar.showsScopeBar = NO; 我也调用
需要帮助来更正此代码。 我有一个带有餐厅名称和地址的核心数据应用程序,有一个搜索栏,它正在运行。我要添加的是一个 Index 和一个 IndexTitle,如下图(箭头)所示。 非常欢迎任何帮助。提前
我正在使用 SearchDisplayController 并希望将样式或色调应用于 searchBar。 但我注意到 SearchDisplayController 更改了我的 searchBar
我当前使用searchBar,我将左侧图标更改为自定义 UIImageView。当按下按钮时我想将其改回原来的搜索图标。 //my custom search iconBar searchBar.se
我在我的电视应用程序中使用自定义搜索屏幕,我的问题是我无法在启动 fragment 时将焦点设置在 SearchBar View 上。我尝试了以下方法: mSearchBar.setFocusable
我想在输入 edittext 内容的 ListView 行中搜索相关的 Row。 如何在 Listview 中获取行..请给我示例代码.. 谢谢 最佳答案 我假设您想根据您键入的 edittext 值
我是一名优秀的程序员,十分优秀!