我正在尝试在我正在处理的网站中实现搜索引擎,而我似乎无法使其正常工作,这可能是一个小错误或我犯的愚蠢错误,有什么建议吗?
我看到的错误是:
未定义的变量:结果(查看:C:\ wamp64 \ www \ webproject \ resources \ views \ search.blade.php)
我对搜索页面的看法:
@extends('layouts.master')
@section('content')
<div class="search_charities_engine">
{!! Form::open(['method'=>'GET','url'=>'charity','class'=>'navbar-form navbar-left','role'=>'search']) !!}
<div class="input-group custom-search-form">
<input type="text" class="form-control" name="search" placeholder="Enter Charity Name...">
<span class="input-group-btn">
<button class="btn btn-default-sm" type="submit">
<i class="fa fa-search"> Search </i>
</button>
</span>
</div>
{!! Form::close() !!}
</div>
@foreach($results as $result)
<article class="charity_info">
<img src="#" style="width: 100px; height: 100px; float: left; margin-right: 25px;">
<h4> {{ $result->name }} </h4>
<p> {{ $result->description}} </p>
<div class="interaction">
<a href="#"> Favourite </a> |
<a href="#"> Edit </a> |
<a href="#"> Donate </a>
</div>
</article>
@endforeach
@endSection
我的路线(web.php) - 此问题中唯一相关的路线是底部2,倒数第二个路线将所有慈善机构输出到不同的页面 - 这有效!:
Route::group(['middleware' => ['web']], function()
{
Route::get('/', function ()
{
return view('welcome');
})->name('home');
Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
Route::post('/signin', [
'uses' => 'UserController@postSignIn',
'as' => 'signin'
]);
Route::get('logout', [
'uses' => 'UserController@getLogout',
'as' => 'logout'
]);
Route::get('profile', [
'uses' => 'UserController@profile',
'as' => 'profile'
]);
Route::post('profile', [
'uses' => 'UserController@updateAvatar',
'as' => 'profile'
]);
Route::get('about', [
'uses' => 'UserController@getAbout',
'as' => 'about'
]);
Route::get('contact', [
'uses' => 'UserController@getContact',
'as' => 'contact'
]);
Route::get('searchPage', [
'uses' => 'UserController@getSearchPage',
'as' => 'searchPage'
]);
Route::get('insert', [
'uses' => 'UserController@getInsert',
'as' => 'insert'
]);
Route::post('store',[
'uses' => 'UserController@postStore',
'as' => 'store'
]);
Route::post('contact', [
'uses' => 'UserController@postContact',
'as' => 'contact'
]);
Route::group(['middleware' => ['auth']], function()
{
Route::get('/dashboard',[
'uses' => 'UserController@getDashboard',
'as' => 'dashboard',
'middleware' => 'auth'
]);
});
Route::resource('charities', 'charityController');
Route::resource('results', 'charityController');
});
我的慈善机构控制器:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\DB;
use App\charity;
class charityController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$charity = charity::all();
return view('charities', ['charities' => $charity]);
$search = \Request::get('search');
$results = charities::where('name','like','%'.$search.'%')
->orderBy('name')
->paginate(20);
return view('search',compact('results'));
}
Laravel比较新,不过我已经通过了文档。
谢谢