0

我正在尝试构建一个搜索功能,它说 users_index 不存在,而它在模型中,App\User.php我不明白为什么它会抛出那个错误?有人可以解释为什么它会抛出错误吗?

错误:索引 users_index 不存在

注意 scout.php 已正确设置为 ALGOLIA_APP_ID 和 ALGOLIA_SECRET' 和'queue' => env('SCOUT_QUEUE', true),

网页.php Route::get('index','SearchController@search')

搜索控制器.php

 namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class SearchController extends Controller
{
public function search(Request $request)
{
    if($request->has('search')){
        $users = User::search($request- 
>get('search'))->get();
    }else{
        $users = User::get();
    }
    return view('index', compact('users'));
}
}

 <body>
<div class="container">
<h1>Laravel Scout Search Tutorial</h1>
<form method="GET" action="{{ url('index') 
}}">
    <div class="row">
        <div class="col-md-6">
            <input type="text" name="search" class="form-control" placeholder="Search">
        </div>
        <div class="col-md-6">
            <button class="btn btn-info">Search</button>
        </div>
    </div>
</form>
<br/>
<table class="table table-bordered">
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Email</th>
    </tr>
    @if(count($users) > 0)
        @foreach($users as $user)
            <tr>
                <td>{{ $user->id }}</td>
                <td>{{ $user->name }}</td>
                <td>{{ $user->email }}</td>
            </tr>
        @endforeach
    @else
        <tr>
            <td colspan="3" class="text- 
danger">Result not found.</td>
        </tr>
    @endif
</table>
</div>
</body>

用户模型

namespace App;

 use Illuminate\Notifications\Notifiable;
 use Illuminate\Contracts\Auth\MustVerifyEmail;
 use Laravel\Scout\Searchable;
  use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Notifiable;
use Searchable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'password',
];

public function searchableAs()
{
    return 'users_index';
}

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

/**
 * The attributes that should be cast to native types.
 *
 * @var array
 */
protected $casts = [
    'email_verified_at' => 'datetime',
];
}
4

1 回答 1

0

忘记在命令行中执行此命令 php artisan scout:import "App\User" 现在可以正常工作

于 2019-02-26T14:59:08.207 回答