Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not enough rights to add an object in Algolia Laravel

I have a problem with using Algolia. Working with database but i can't save it in to API Algolia.com. I tried to search through google but i didn't get any results for this problem.

My controller:

public function store(Request $request)
{
    $role = new Role;

    $role->name = $request->name;
    $role->save();
}

My model:

<?php

namespace App;

use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    use Searchable;

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

    /**
     * Get the index name for the model.
     *
     * @return string
     */
    public function searchableAs()
    {
        return 'roles_index';
    }
}
like image 602
Overload Avatar asked Jan 03 '18 11:01

Overload


1 Answers

In you env file, make sure you are setting the admin key as the ALGOLIA_SECRET.

By default, Algolia gives you different key:

  • Search key, which can only perform search (read) operations.
  • Write key, which can index (write) data.
  • Admin key, which can do everything. This is the recommended one for Laravel Scout.

Please note that only the search key can be passed to your frontend, if you use Vue InstantSearch for instance.

Screenshot Algolia Keys in the dashboard

Please let me know if that solved your issue.

like image 177
Julien Bourdeau Avatar answered Sep 24 '22 06:09

Julien Bourdeau