索引users_index不存在laravel scout

问题描述 投票:0回答:1

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

错误:索引users_index不存在

注意scout.php使用ALGOLIA APP ID和ALGOLIA SECRET'和'queue' => env('SCOUT_QUEUE', true),正确设置

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

searchcontroller.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',
];
}
php laravel-5 laravel-5.7 algolia laravel-scout
1个回答
0
投票

忘了在命令行php artisan scout:import "App\User"中执行此命令,它现在工作正常

© www.soinside.com 2019 - 2024. All rights reserved.