SmokeTM
1 week ago
245
26
Laravel

Adding relationship to algolia index throws exception

Posted 1 week ago by SmokeTM

Hi guys trying to index my relationships at algolia but no success, always get exception thrown Undefined property: Illuminate\Database\Eloquent\Relations\HasOne::$type

Relationship:

//in the toSearchableArray()
// Add Relationship to algolia record
        $record['type'] = $this->type()->type;
        $record['job_level'] = $this->job_level()->job_level;
        $record['region'] = $this->region()->region;
        $record['country'] = $this->country()->country;

  /**
     * Get the type record associated with the user.
     */
    public function type()
    {
        return $this->hasOne('App\Type', 'id', 'type');
    }

    /**
     * Get the job_level record associated with the user.
     */
    public function job_level()
    {
        return $this->hasOne('App\JobLevel', 'id', 'job_level');
    }

    /**
     * Get the region record associated with the user.
     */
    public function region()
    {
        return $this->hasOne('App\Region', 'id', 'region');
    }

    /**
     * Get the country record associated with the user.
     */
    public function country()
    {
        return $this->hasOne('App\Country', 'id', 'country');
    }

My migration looks like that

  public function up()
    {
        Schema::create('types', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('type');
        });
    }

I did it like in the docs descriped?

Best

Please sign in or create an account to participate in this conversation.