Not enough rights to add an object in Algolia Laravel
Asked Answered
M

1

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';
    }
}
Methanol answered 3/1, 2018 at 11:6 Comment(3)
What have you tried to save the data? Is there any error message given?Mammilla
@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.Methanol
@NicoHaase In document laravel, by default, when i add new a record, alogoli will automatically add in algolia.com.Methanol
D
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.

Dorr answered 3/1, 2018 at 13:23 Comment(1)
this solved my problem and you saved my day thank youYwis

© 2022 - 2024 — McMap. All rights reserved.