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

Syntax error, unexpected token "readonly" #159

Closed
Bryan-Lund opened this issue Jan 19, 2022 · 2 comments
Closed

Syntax error, unexpected token "readonly" #159

Bryan-Lund opened this issue Jan 19, 2022 · 2 comments

Comments

@Bryan-Lund
Copy link

I've only recently started using this package and I think there's an issue with the LaravelJsonApi\Eloquent\Contracts\ReadOnly interface and LaravelJsonApi\Eloquent\Fields\Concerns\ReadOnly trait in PHP 8.1 due to readonly properties that were added: https://php.watch/versions/8.1/readonly:

I followed the tutorial and when I try to clear the cache via artisan, I get the following message:

  syntax error, unexpected token "readonly"

  at vendor/laravel-json-api/eloquent/src/Contracts/Fillable.php:24
     20▕ namespace LaravelJsonApi\Eloquent\Contracts;
     21▕
     22▕ use Illuminate\Database\Eloquent\Model;
     23▕
  ➜  24▕ interface Fillable extends ReadOnly

The line in my file which it then points to is the ID::make(), in the default fields function from generating a schema through artisan jsonapi:schema and looking at the LaravelJsonApi\Eloquent\Fields\ID field class, it implements the LaravelJsonApi\Eloquent\Contracts\Fillable interface which extends LaravelJsonApi\Eloquent\Contracts\ReadOnly

Out of curiosity, I tried changing LaravelJsonApi\Eloquent\Contracts\ReadOnly's interface's file name and interface to ReadOnlyTest as well as updating the LaravelJsonApi\Eloquent\Fields\ID class to match and it worked fine. After this, it failed on another field because it tried to use the LaravelJsonApi\Eloquent\Fields\Concerns\ReadOnly class.

I think the ReadOnly trait / interface (and any other ReadOnly classes etc that I might have missed) should be updated for supporting PHP 8.1.

Thanks in advance

@lindyhopchris
Copy link
Contributor

Hi! See #138 - I haven't tagged PHP 8.1 version yet. So you either need to use PHP 8.0 or follow the instructions in the linked issue as to how to install the dev version of the next tag (that works with 8.1).

I should be tagging 8.1 support in the next week or so - I'm just waiting for Laravel 9 to come out as it's not worth me tagging a major for PHP 8.1 and then having to tag another major very soon after for Laravel 9. So I'm hoping to combine both of them into one major release.

@Bryan-Lund
Copy link
Author

Bryan-Lund commented Jan 19, 2022

Ok, great. Thanks for that!

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