tailflow / laravel-orion

The simplest way to create REST API with Laravel

Home Page:https://orion.tailflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Include not working in search endpoints

BobJjilak opened this issue · comments

Hi, I've been using Orion for my REST API and since a few days I got a weird behavior.

I'm triggering a request from my front end

fetchCompaniesByActivity(page, search, expertId, cabinetId) {
        const includes = ['mainContact', 'links', 'meetings'];

        const options = {
            include: includes.join(','),
            limit: 10,
            scopes: [
                { name: 'involved', parameters: [expertId] },
                { name: 'cabinet', parameters: [cabinetId] },
                { name: 'active', parameters: [] }
            ],
            sort: [
                { field: 'updated_at', direction: 'desc' }
            ]
        };

        return axios.post(`${API_URL}/companies/search`, options);
    }

Got this in my controller :

public function includes(): array
 {
     return [
         'experts',
         'mainEntrepreneur',
         'mainContact',
         'links',
         'users',
         'users.roles',
         'years',
         'years.months',
         'years.months.graphs',
         'years.months.objectives',
         'years.months.results',
         'years.graphs',
         'years.indicators',
         'years.objectives',
         'managers',
         'managers.roles',
         'experts',
         'experts.roles',
         'location',
         'meetings',
         'meetings.actions',
         'meetings.facts',
         'meetings.participants',
         'meetings.expert',
         'newMessages',
         'newDocuments'
     ];
 }

And this is my relation

public function mainContact(): HasOneThrough
    {
        return $this->hasOneThrough(User::class, UserRole::class, 'company_id', 'id', 'id', 'user_id')
            ->whereIn('role_id', [UserRole::ROLE_CABINET_USER, UserRole::ROLE_ENTREPRENEUR])
            ->where('is_admin', true);
    }

What is weird is that on my local env, it loads the include, but on my test server, the includes are not loaded. What is strange is that when I edit orion RelationResolver, I don't know why it seems to fix it without any changes...

Hi @DavidSprauel,

Please refer to the correct syntax for using includes in the body of request: https://tailflow.github.io/laravel-orion-docs/v2.x/guide/search.html#includes

Includes prior to v2.17.0 were intended to be used solely via query parameters - it is incorrect to be using include as a post parameter prior v2.17.0 to begin with.