Comments (5)
Hi! I wouldn't ever recommend creating a new request within an existing Laravel request, as Laravel assumes it is only handling one request at once.
Why don't you just update the user model yourself? Why do you have to pass it off as a JSON:API process?
from laravel-json-api.
@lindyhopchris
Okay, thanks for your reply.
I want to reuse the api endpoints. And i want also to benefit of the already implemented validations and rules in place in this api endpoint.
I already used this logic for the passport api without trouble like this:
<?php
namespace App\Http\Controllers\Api\V1\Auth;
use Illuminate\Support\Facades\DB;
use App\Http\Requests\Api\V1\Auth\LoginRequest;
use CloudCreativity\LaravelJsonApi\Document\Error\Error;
use CloudCreativity\LaravelJsonApi\Http\Controllers\JsonApiController;
use Illuminate\Support\Facades\Request;
class LoginController extends JsonApiController
{
/**
* Handle the incoming request.
*
* @param LoginRequest $request
* @return mixed
*/
public function __invoke(LoginRequest $request)
{
$client = DB::table('oauth_clients')->where('password_client', 1)->first();
$oauthRequest = Request::create(
route('passport.token', [], false),
'POST',
[
'grant_type' => 'password',
'client_id' => $client->id,
'client_secret' => $client->secret,
'username' => $request->email,
'password' => $request->password,
'scope' => '',
],
);
$response = app()->handle($oauthRequest);
if ($response->status() == 200) {
return json_decode((string)$response->getContent(), true);
} else {
$error = json_decode((string)$response->getContent(), true);
return $this->reply()->errors([
Error::fromArray([
'title' => 'Bad Request',
'detail' => $error['message'],
'status' => '400',
])
]);
}
}
}
```
from laravel-json-api.
Sending a request within another request is just not something I'd recommend doing. Using the HTTP client would seem like a lot better idea.
I think this shows a need for a developer being able to execute a JSON:API "operation" wherever they want. This is something I'd support in a future version, as I need to separate out the operations to support the Atomic Operations extension. However, at the moment that's not something that's supportable in the current codebase as the operations are coupled to the HTTP requests due to using form request classes.
from laravel-json-api.
Okay thanks, i will go with the http client then.
Thanks
from laravel-json-api.
I'm going to leave this open as a reminder that I need to make it easier for developers to manually trigger a JSON:API operation.
from laravel-json-api.
Related Issues (20)
- Unable to create json api resource with attribute name "type" HOT 3
- Self-relation doesn't include model fields HOT 5
- Arguement 3 passed to controller must be an instance of model, string given
- Support for multiple operations in a single request HOT 2
- use Errors Handling in Laravel 8 HOT 1
- Why does json-api trimming spaces in my attributes when updating? HOT 3
- filter slug and underscore HOT 1
- Multiple primary keys - Mysql Error HOT 1
- Sparse fieldsets not working with included relationships HOT 3
- How to attach a middleware to a specific resource relationship? HOT 3
- How I can filter included resources by their fields HOT 8
- Migrate from cloudcreativity/laravel-json-api to laravel-json-api/laravel HOT 15
- How to stop this library from making asterix queries? HOT 1
- Insert on duplicate key upd when inserting a record? HOT 6
- Handle HasMany relationship with extra field. HOT 2
- [5.x] Missing meta HOT 8
- bug: service provider boot throws "No application encryption key has been specified." HOT 1
- Error in tests HOT 1
- getResourceLinks function HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-json-api.