8

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';
    }
}
Overload
  • 81
  • 2
  • What have you tried to save the data? Is there any error message given? – Nico Haase Jan 03 '18 at 11:12
  • @NicoHaase Hi. Error is: AlgoliaSearch \ AlgoliaException (400) Not enough rights to add an object near line:1 column:181. Save in to database working but i can't add record in API algolia. – Overload Jan 03 '18 at 11:20
  • @NicoHaase In document laravel, by default, when i add new a record, alogoli will automatically add in algolia.com. – Overload Jan 03 '18 at 11:22

1 Answers1

11

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.

Julien Bourdeau
  • 1,193
  • 11
  • 17