Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detach[Model] has empty parameter #604

Open
JM-TarikHacialiogullari opened this issue Apr 16, 2024 · 1 comment
Open

Detach[Model] has empty parameter #604

JM-TarikHacialiogullari opened this issue Apr 16, 2024 · 1 comment

Comments

@JM-TarikHacialiogullari
Copy link

JM-TarikHacialiogullari commented Apr 16, 2024

Hello!

We use the Restify library, today I encountered a weird issue, maybe it could be due to me or a bug.

This is a snippet for my JobPolicy.php:

    public function attachCategories(User $user, Job $job): bool
    {
        ....(some checks on $job->project_id)
        return true;
    }

    public function detachCategories(User $user, Job $job): bool
    {
        ....(some checks on $job->project_id)
        return true;
    }

It happened when I test the attach and detach:

test('marketeer can detach category from job', function () {
    logInWithProject($this->project->fresh());

    $job = Job::factory()->create();

    $category = Category::factory()->create();

    postJson(JobRepository::route($job->id.'/attach/categories'), [
        'categories' => [$category->id],
    ])->assertCreated();

    postJson(JobRepository::route($job->id.'/detach/categories'), [
        'categories' => [$category->id],
    ])->assertNoContent();

    expect(JobCategory::all()->count())->toBe(0);
});

The problem I face is, the attach $job parameter is correct. but the detach $job parameter is an empty job model.

I tried inside the test to debug:

$get = getJson(JobRepository::route($job->id))->assertOk()->json()
dd($get);

The get returns correctly the job, so I am not sure where the problem is, maybe it could be within restify.

Reproducing this error:

You can reproduce this by doing dd($job) or dd($job->toArray()) inside the detachCategories it will return empty job model or []. but in attach it will return the correct job.

@JM-TarikHacialiogullari
Copy link
Author

JM-TarikHacialiogullari commented Apr 16, 2024

Secondly I have noticed a small typo in the in the documentation:
image
detachPost*
Source: https://restify.binarcode.com/auth/authorization#allow-detach

Thirdly, I really like this library its awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant