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

Can't explain this issue, 500 status code with response 1 #158

Closed
ionut-tanasa opened this issue Jan 18, 2022 · 5 comments
Closed

Can't explain this issue, 500 status code with response 1 #158

ionut-tanasa opened this issue Jan 18, 2022 · 5 comments

Comments

@ionut-tanasa
Copy link

ionut-tanasa commented Jan 18, 2022

hi there :)

i am trying to set up this package and follow the tutorial on the docs.

i am running in a strange issue when i register the route

JsonApiRoute::server('v1')->prefix('v1')->resources(function ($server) {
    $server->resource('users', JsonApiController::class)->readOnly();
});

I followed every step in the tutorial and just did a resource (User instead of Post) to play around.

If I don't register the route i get the correct response:

{
    "jsonapi": {
        "version": "1.0"
    },
    "errors": [
        {
            "status": "404",
            "title": "Non trovato"
        }
    ]
}

If i register the route it stops working. Giving an error 500 and no response (Postman shows 1)

Screenshot 2022-01-18 at 22 35 15

Running on PHP 8.1.0 and the following are my composer dependencies:

Screenshot 2022-01-18 at 22 36 26

How can I even debug this? Could it be a Sail issue?

Thanks

@ionut-tanasa
Copy link
Author

On further debugging i managed to discover the following:

laravel.test_1  |   syntax error, unexpected token "readonly"
laravel.test_1  | 
laravel.test_1  |   at vendor/laravel-json-api/eloquent/src/Contracts/Fillable.php:24
laravel.test_1  |      20▕ namespace LaravelJsonApi\Eloquent\Contracts;
laravel.test_1  |      21▕ 
laravel.test_1  |      22▕ use Illuminate\Database\Eloquent\Model;
laravel.test_1  |      23▕ 
laravel.test_1  |   ➜  24▕ interface Fillable extends ReadOnly
laravel.test_1  |      25▕ {
laravel.test_1  |      26▕ 
laravel.test_1  |      27▕     /**
laravel.test_1  |      28▕      * Does the model need to exist in the database before the attribute is filled?
laravel.test_1  | 
laravel.test_1  |       +4 vendor frames 
laravel.test_1  |   5   app/JsonApi/V1/Users/UserSchema.php:31
laravel.test_1  |       Composer\Autoload\ClassLoader::loadClass()
laravel.test_1  | 
laravel.test_1  |       +9 vendor frames 
laravel.test_1  |   15  routes/api.php:25
laravel.test_1  |       LaravelJsonApi\Laravel\Routing\PendingResourceRegistration::__destruct()
laravel.test_1  | 2022-01-18 21:48:26,738 INFO success: php entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
laravel.test_1  | 2022-01-18 21:48:26,738 INFO exited: php (exit status 1; not expected)
<?php

namespace App\JsonApi\V1\Users;

use App\Models\User;
use LaravelJsonApi\Eloquent\Contracts\Paginator;
use LaravelJsonApi\Eloquent\Fields\DateTime;
use LaravelJsonApi\Eloquent\Fields\ID;
use LaravelJsonApi\Eloquent\Filters\WhereIdIn;
use LaravelJsonApi\Eloquent\Pagination\PagePagination;
use LaravelJsonApi\Eloquent\Schema;

class UserSchema extends Schema
{

    /**
     * The model the schema corresponds to.
     *
     * @var string
     */
    public static string $model = User::class;

    /**
     * Get the resource fields.
     *
     * @return array
     */
    public function fields(): array
    {
        return [
            ID::make(),
        ];
    }

    /**
     * Get the resource filters.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            WhereIdIn::make($this),
        ];
    }

    /**
     * Get the resource paginator.
     *
     * @return Paginator|null
     */
    public function pagination(): ?Paginator
    {
        return PagePagination::make();
    }

}

@X-Coder264
Copy link
Contributor

This package does not support PHP 8.1 yet.

#156
#138

@ionut-tanasa
Copy link
Author

@X-Coder264

forgot to mention i downgraded to 8.0

@X-Coder264
Copy link
Contributor

X-Coder264 commented Jan 18, 2022

I'm not sure that you did because

syntax error, unexpected token "readonly"

can only happen on PHP 8.1 as readonly is a reserved keyword only on PHP 8.1 due to the read only feature

Or maybe you now have a different error?

@ionut-tanasa
Copy link
Author

@X-Coder264 😅 sail didn't downgrade it properly ... i'll try to fix it now.

but if it works for everybody else that is the issue :)

thank you very much and sorry for stealing precious time from ya

closing.

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

2 participants