-
Notifications
You must be signed in to change notification settings - Fork 109
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
Laravel 5.3 support #13
Comments
@egeriis only just looking at the 5.3 upgrade notes now. Does it definitely not work with the method signature as is? I wasn't sure whether the upgrade guide saying "you may remove the arguments..." meant it was optional? If that's the only breaking thing then I'm happy to release a new version of v0.2 as it's a fairly straightforward change. I probably won't be able to test it though because all the apps I have are currently on the v0.4 (latest) version. If I make the change would you be able to try it out for me? I probably wouldn't tag it though until Laravel 5.3 is officially released - though I believe that's going to be very soon. |
ah, just seen that 5.3 was released yesterday 😄 |
@egeriis the 5.3 docs are still saying that dependency injection can be used for the So not sure this change is required? |
There must be something else broken then. I did a bunch of debugging yesterday, my conclusion so far is that something is breaking the json-api middleware. I don't know if it works for v0.4 though, as we're in the middle of upgrading our API to use this version. Let me get back when that upgrade is done—should be by the end of this week. Then I'll attempt a L5.3 upgrade from this branch. |
I can upgrade one of the apps that I've got v0.4 in sometime this week as well, so hopefully between the two of us we can work out if any changes are required! |
Sounds great! I'll see if I can get some work done on this one of the coming days. |
@egeriis yeah, the package is not working in 5.3, but not to do with the service providers. Basically, a controller's constructor is now being invoked before middleware is run, which means that the request that is injected into the controller is being validated before the Basically if we want to keep a single request class per resource type, I'm going to have to remove the In the meantime I'm going to tie |
For Laravel 5.3, it is necessary to use controller middleware to run the validation of the HTTP request once for a specific resource type. This commit refactors the architecture so that: 1. JSON API suppprt is initiated and as HTTP content is parsed for conformance to the spec. This happens in route middleware and has no knowledge of what specific resource type is the subject of the request. This process does content negotiation, parses encoding parameters and parses document content checking it conforms to the spec. 2. Other application middleware is now executed, knowing that any exceptions thrown will be cast to JSON API errors. 3. The JSON API request is finalised with knowledge of what resource type is expected. A JSON API request object is built from all finalised parameters, and then this is validated according to business logic. This is all done by a new piece of middleware - `json-api-request` - that is registered as controller middleware as that is the only point at which the specific resource type is known, plus therefore the business rules for validating request parameters and content. Refer to issue #13
This is now working with Laravel 5.3 - I've implemented on the Laravel JSON API demo app here: I still need to test it on a few other apps, so there might still be kinks to iron out! To use it in the meantime, add the following to your
Then:
|
Sounds great. We are almost done with our refactoring, so we can attempt an upgrade to L5.3 :) |
@egeriis just a quick heads up - I push a change to the dev branches that broke it. It's a minor thing but I won't be able to fix it until tonight (UK time). Just so you don't waste your time trying to get it working! Will post here again when I've push the fix. |
Ok, the demo app is working again. Let me know if you have any problems |
Trying to follow your demo example but it seems to require some things I don't see in laravel-json-api. For example, AbstractRequestHandler doesn't exist in 0.5.x-dev's latest commit. (Demo has the composer.lock @ 9a7cb63). |
@nokios try switching the demo app to the |
@lindyhopchris An update from here, we're finalizing our update to 0.4. As we're done, I'll find an off-hours time to check this out :) |
Appears that |
@egeriis good spot - thanks! Any other problems or all ok so far? |
Everything seems fine. We looked through the changelog, and it appears that everything we needed was mentioned there. |
Looks like there's an error in |
It would also appear that |
Thanks, have fixed the upgrade guide. At the moment |
I was just looking at |
makes sense. I'm planning at some point to separate I'm likely to be tagging this today or Monday, unless there's any last minute objections?! Obviously it's still a development release so there's still plenty of chances to improve things, though I'd like to keep the breaking changes a lot less between each development release in the future (as this one has been bigger than expected due to the Laravel 5.3 changes). |
I am not sure I understand this section: https://github.com/cloudcreativity/laravel-json-api/blob/develop/UPGRADE.md#search-all My controllers already have Model, Hydrator and SearchInterface as arguments. Where does SearchAll go? |
I am upgrading our big API right now, so I'll let you know today if there are any major breaking things for us :) |
Re: search all... it means if you're not using a custom Cool, well I'll probably wait until Monday to tag then as I don't need to do it today. That gives you a chance to raise any problems - your input is really helpful! |
Wrong namespace for |
Thanks, have fixed that |
Upgrade guide seems to me missing what to do about the removed |
More specifically, how do I replace |
Hold your horses, I reckon this code I have is due to a previous caveat. |
Good point, at the moment it isn't passed down through the hooks. It is possible to do so because the resource is passed to the I'm thinking the hooks probably do need the resource as their second argument - what do you think? |
@egeriis I'm going to add the passing of the incoming resource down the model hooks, then tag. Sound ok or did you have anything else to raise at this point? |
Don't seem to have any other findings. Makes sense to have the resource passed into the model hooks. |
@lindyhopchris Oh, I have this question :) I used to do this, in the public function getResourceId()
{
$id = $this
->getHttpRequest()
->route(ResourceRegistrar::PARAM_RESOURCE_ID);
if ($id === 'me') {
return Auth::user()->getKey();
}
return $id;
} The purpose being that a request to |
The resource identifier (type/id) is now checked a lot further up the stack. This is done via the store, which delegates to adapters, of which the default one provided by the package is the Eloquent adapter. To use a "custom" id for a user, you'll need to attach an adapter for your user model, rather than using the Eloquent adapter to resolve the id. Something along these lines: <?php
namespace App\JsonApi\User;
use CloudCreativity\JsonApi\Contracts\Store\AdapterInterface;
use CloudCreativity\JsonApi\Contracts\Object\ResourceIdentifierInterface;
use Illuminate\Contracts\Auth\Guard;
class Adapter implements AdapterInterface
{
private $auth;
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
public function recognises($resourceType)
{
return 'users' === $resourceType;
}
public function exists(ResourceIdentifierInterface $identifier)
{
$id = $identifier->getId();
if ('me' === $id) {
return $this->auth->check();
}
return User::exists('id', $id);
}
public function find(ResourceIdentifierInterface $identifier)
{
$id = $identifier->getId();
if ('me' === $id) {
return $this->auth->user();
}
return User::find($id);
}
} Remove the user model from your Eloquent adapter config, and then attach your custom adapter in your |
Closing - v0.5.0 released |
So rather than pointing 'user' to Edit: Never mind, I get it now. It's a new feature :) |
It would be nice to get an update with support for Laravel 5.3. Looks like the service provider needs to have it's dependency injection removed from the method signature.
https://laravel.com/docs/5.3/upgrade
We're currently using v0.2, so if an update could be issued to this version, that would be great.
The text was updated successfully, but these errors were encountered: