【问题标题】:Index users_index does not exist laravel scout索引 users_index 不存在 laravel scout
【发布时间】:2019-02-26 14:42:04
【问题描述】:

我正在尝试构建一个搜索功能,它说 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】:

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

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 1970-01-01
      • 2017-10-19
      • 2023-03-10
      • 1970-01-01
      • 2021-08-16
      • 2018-06-19
      • 2018-12-12
      • 1970-01-01
      相关资源
      最近更新 更多