cURL error 28: Operation timed out after 10000 milliseconds - laravel

I've problem with Guzzle HTTP client,
when i send post request manually (using postman) to oauth/token, i get the token and refresh token correctly but when i request sent using guzzle, it freezes and do not get any response for a while, after timeout return exception bottom
"message": "cURL error 28: Operation timed out after 10000 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)",
"exception": "GuzzleHttp\\Exception\\ConnectException",
"file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
"line": 200,
"trace": [
{
"file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
"line": 155,
"function": "createRejection",
"class": "GuzzleHttp\\Handler\\CurlFactory",
"type": "::"
},
{
"file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
"line": 105,
"function": "finishError",
"class": "GuzzleHttp\\Handler\\CurlFactory",
"type": "::"
},
{
"file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlHandler.php",
"line": 43,
"function": "finish",
"class": "GuzzleHttp\\Handler\\CurlFactory",
"type": "::"
....
this is my code
$client = new \GuzzleHttp\Client([
'timeout' => 10
]); //GuzzleHttp\Client
try {
$result = $client->post(url('oauth/token'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => $this->_client_id,
'client_secret' => $this->_client_secret,
'username' => $user->username,
'password' => $req->password,
// 'scope' => $scopes
]
]);
} catch (\Guzzle\Http\Exception\ConnectException $e) {
$response = json_encode((string)$e->getResponse()->getBody());
}
what should i do?

Check for your firewall if it's active and disable it
sudo ufw disable
sudo ufw disable

Related

Cannot send an empty message 50006 when using multipart Laravel Http post

I am getting this error when trying to send a message to a Discord webhook.
{"message": "Cannot send an empty message", "code": 50006}
I've read the discord documentation on sending images, and can honestly not see what I'm doing wrong.
Here's the code I'm running:
Http::withHeaders([
'Content-Type' => 'multipart/form-data; boundary=--abcdefghijklmnop'
])
->asMultipart()
->post(
$this->webhookUrl,
[
[
'name' => 'payload_json',
'contents' => '{
"content": "Hello, World!",
"embeds": [{
"title": "Hello, Embed!",
"description": "This is an embedded message.",
"thumbnail": {
"url": "attachment://image1.jpg"
},
"image": {
"url": "attachment://image2.jpg"
}
}],
"attachments": [{
"id": 0,
"description": "Image of a cute little cat",
"filename": "image1.jpg"
}, {
"id": 1,
"description": "Rickroll gif",
"filename": "image2.jpg"
}]
}',
'headers' => [
'Content-Type' => 'application/json',
]
],
[
'name' => 'image1.jpg',
'contents' => 'data:image/jpeg;base64,[[encoded image]]',
'headers' => [
'Content-Type' => 'image/jpeg',
]
],
[
'name' => 'image2.jpg',
'contents' => 'data:image/jpeg;base64,[[encoded image]]',
'headers' => [
'Content-Type' => 'image/jpeg',
]
]
];
);
As you can see, this is basically the message they use in their documentation as an example and I've just translated it to be sent with the Http facade.
What am I missing?

Laravel API Request - “Unauthorized”

Good day to you all,
Today I decided to authenticate my experimental api. I installed Passport, but I get a constant response:
{
error: {
message: "Unauthorized"
}
}
I tried disable it, and just use in api.php:
Route::get('test', function (){
return 1;
});
As a testing point, but still I get the same message, so I assume it has nothing to do with the Passport package.
Kernel.php:
<?php
namespace App\Http;
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\Cors;
use App\Http\Middleware\CrossDomain;
use App\Http\Middleware\EncryptCookies;
use App\Http\Middleware\ForceJsonResponse;
use App\Http\Middleware\isAdmin;
use App\Http\Middleware\isCompany;
use App\Http\Middleware\RedirectIfAuthenticated;
use App\Http\Middleware\TrimStrings;
use App\Http\Middleware\TrustProxies;
use App\Http\Middleware\VerifyCsrfToken;
use Cog\Laravel\Ban\Http\Middleware\ForbidBannedUser;
use Cog\Laravel\Ban\Http\Middleware\LogsOutBannedUser;
use Fruitcake\Cors\HandleCors;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
use Illuminate\Auth\Middleware\RequirePassword;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance;
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
use Illuminate\Http\Middleware\SetCacheHeaders;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Routing\Middleware\ValidateSignature;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use RenatoMarinho\LaravelPageSpeed\Middleware\ElideAttributes;
use RenatoMarinho\LaravelPageSpeed\Middleware\InlineCss;
use RenatoMarinho\LaravelPageSpeed\Middleware\InsertDNSPrefetch;
use RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* #var array
*/
protected $middleware = [
TrustProxies::class,
HandleCors::class,
PreventRequestsDuringMaintenance::class,
ValidatePostSize::class,
TrimStrings::class,
ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* #var array
*/
protected $middlewareGroups = [
'web' => [
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
CrossDomain::class,
InlineCss::class,
ElideAttributes::class,
InsertDNSPrefetch::class,
RemoveComments::class,
//CollapseWhitespace::class,
//DeferJavascript::class,
],
'api' => [
//'throttle:api',
SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* #var array
*/
protected $routeMiddleware = [
'auth' => Authenticate::class,
'auth.basic' => AuthenticateWithBasicAuth::class,
'cache.headers' => SetCacheHeaders::class,
'can' => Authorize::class,
'guest' => RedirectIfAuthenticated::class,
'password.confirm' => RequirePassword::class,
'signed' => ValidateSignature::class,
'throttle' => ThrottleRequests::class,
'verified' => EnsureEmailIsVerified::class,
'forbid-banned-user' => ForbidBannedUser::class,
'logs-out-banned-user' => LogsOutBannedUser::class,
'is_admin' => isAdmin::class,
'is_company' => isCompany::class,
'json.response' => ForceJsonResponse::class,
'cors' => Cors::class,
];
}
config/auth.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
routes/api.php:
<?php
use Illuminate\Support\Facades\Route;
Route::get('test', function () {
return 1;
});
Route::group(['middleware' => ['cors', 'json.response']], function () {
Route::group(['prefix' => 'auth'], function () {
Route::post('login', 'Api\AuthController#login');
Route::group(['middleware' => 'auth:api'], function () {
Route::get('logout', 'Api\AuthController#logout');
Route::get('user', 'Api\AuthController#user');
});
});
Route::group(['middleware' => 'auth:api'], function () {
// Companies
Route::group(['prefix' => 'provider/company'], function () {
Route::post('store', 'Api\Provider\CompanyController#store');
Route::get('show/{id}', 'Api\Provider\CompanyController#show');
Route::patch('update', 'Api\Provider\CompanyController#update');
Route::delete('destroy/{id}', 'Api\Provider\CompanyController#destroy');
Route::get('branches/{id}', 'Api\Provider\CompanyController#branches');
});
// Branches
Route::group(['prefix' => 'provider/branch'], function () {
Route::post('store', 'Api\Provider\BranchController#store');
Route::get('show/{id}', 'Api\Provider\BranchController#show');
Route::patch('update', 'Api\Provider\BranchController#update');
Route::delete('destroy/{id}', 'Api\Provider\BranchController#destroy');
Route::get('classifieds/{id}', 'Api\Provider\BranchController#classifieds');
});
// Classifieds
Route::group(['prefix' => 'provider/classified'], function () {
Route::post('store', 'Api\Provider\ClassifiedController#store');
Route::get('show/{identifier}', 'Api\Provider\ClassifiedController#show');
Route::patch('update', 'Api\Provider\ClassifiedController#update');
Route::delete('destroy/{identifier}', 'Api\Provider\ClassifiedController#destroy');
});
// Attributes
Route::group(['prefix' => 'provider/data'], function () {
Route::get('categories', 'Api\Provider\DataController#categories');
Route::get('attributes/{parent_id}', 'Api\Provider\DataController#attributes');
});
});
});
Error Stack:
{
message: "Too Many Attempts.",
exception: "Illuminate\Http\Exceptions\ThrottleRequestsException",
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
line: 200,
trace: [
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
line: 121,
function: "buildException",
class: "Illuminate\Routing\Middleware\ThrottleRequests",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
line: 63,
function: "handleRequest",
class: "Illuminate\Routing\Middleware\ThrottleRequests",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "Illuminate\Routing\Middleware\ThrottleRequests",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 103,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
line: 697,
function: "then",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
line: 672,
function: "runRouteWithinStack",
class: "Illuminate\Routing\Router",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
line: 636,
function: "runRoute",
class: "Illuminate\Routing\Router",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
line: 625,
function: "dispatchToRoute",
class: "Illuminate\Routing\Router",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
line: 166,
function: "dispatch",
class: "Illuminate\Routing\Router",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 128,
function: "Illuminate\Foundation\Http\{closure}",
class: "Illuminate\Foundation\Http\Kernel",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\app\Http\Middleware\ForceJsonResponse.php",
line: 20,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "App\Http\Middleware\ForceJsonResponse",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\renatomarinho\laravel-page-speed\src\Middleware\PageSpeed.php",
line: 28,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "RenatoMarinho\LaravelPageSpeed\Middleware\PageSpeed",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\renatomarinho\laravel-page-speed\src\Middleware\PageSpeed.php",
line: 28,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "RenatoMarinho\LaravelPageSpeed\Middleware\PageSpeed",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\renatomarinho\laravel-page-speed\src\Middleware\PageSpeed.php",
line: 28,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "RenatoMarinho\LaravelPageSpeed\Middleware\PageSpeed",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\renatomarinho\laravel-page-speed\src\Middleware\PageSpeed.php",
line: 28,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "RenatoMarinho\LaravelPageSpeed\Middleware\PageSpeed",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\renatomarinho\laravel-page-speed\src\Middleware\PageSpeed.php",
line: 28,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "RenatoMarinho\LaravelPageSpeed\Middleware\PageSpeed",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\renatomarinho\laravel-page-speed\src\Middleware\PageSpeed.php",
line: 28,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "RenatoMarinho\LaravelPageSpeed\Middleware\PageSpeed",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\fruitcake\laravel-cors\src\HandleCors.php",
line: 57,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "Fruitcake\Cors\HandleCors",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php",
line: 21,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull.php",
line: 31,
function: "handle",
class: "Illuminate\Foundation\Http\Middleware\TransformsRequest",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php",
line: 21,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TrimStrings.php",
line: 40,
function: "handle",
class: "Illuminate\Foundation\Http\Middleware\TransformsRequest",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "Illuminate\Foundation\Http\Middleware\TrimStrings",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php",
line: 27,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "Illuminate\Foundation\Http\Middleware\ValidatePostSize",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php",
line: 86,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\fideloper\proxy\src\TrustProxies.php",
line: 57,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 167,
function: "handle",
class: "Fideloper\Proxy\TrustProxies",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
line: 103,
function: "Illuminate\Pipeline\{closure}",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
line: 141,
function: "then",
class: "Illuminate\Pipeline\Pipeline",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
line: 110,
function: "sendRequestThroughRouter",
class: "Illuminate\Foundation\Http\Kernel",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\public\index.php",
line: 55,
function: "handle",
class: "Illuminate\Foundation\Http\Kernel",
type: "->"
},
{
file: "C:\Users\lopes\PhpstormProjects\Ocasiao-CMS\server.php",
line: 21,
function: "require_once"
}
]
}
Can any of you give me a hint or explanation on how to fix this/
If you removed Auth middleware but still getting unauthorized means there may be route cache. Try using php artisan route:clear and check.
I just realised there was another package installed conflicting with this one.
Thank you all!

return user model with eager loading laravel

return $data =InteractiveSession::with('messages.user')->where('exercise_id',$exercise->id)->first();
This code will return data like below
{
"id": 1,
"exercise_id": 48,
"messages": [
{
"id": 1,
"from_user": 69,
"message": "Hi",
"interactive_session_id": 1,
"user": {
"id": 69,
"first_name": "Jobin"
}
}
]}
how can i return data like below??
{
"id": 1,
"exercise_id": 48,
"messages": [
{
"id": 1,
"from_user":{
"id": 69,
"first_name": "Jobin"
},
"message": "Hi",
"interactive_session_id": 1,
}
]}
i have tables interactivesession,message,users, using hasmany relation
You can create a relation for from_user to the user model, and then do return $data = InteractiveSession::with(['messages.user', 'fromUser'])->where('exercise_id',$exercise->id)->first(); (remember fromUser should be your relation name)
Try this:
$data = InteractiveSession::with('messages.user')->where('exercise_id',$exercise->id)->first();
$data->transform(function($record) {
$messages = $record->messages->transform(function($message) {
'id' => $message->id,
'from_user' => [
'id' => $message->user->id,
'first_name' => $message->user->first_name
],
'message' => $message->message,
'interactive_session_id' => $message->interactive_session_id
});
return [
'id' => $record->id,
'exercise_id' => $record->exercise_id,
'messages' => $messages
];
});

Trying to get property 'resource' of non-object in PaginatedResourceResponse.php after Laravel-update

actually I am getting this error after updating Laravel from v7.5.1 to v7.6.2
"message": "Trying to get property 'resource' of non-object",
"exception": "ErrorException",
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Http/Resources/Json/PaginatedResourceResponse.php",
"line": 29,
"trace": [
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Http/Resources/Json/PaginatedResourceResponse.php",
"line": 29,
"function": "handleError",
"class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
"type": "->"
},
{
"function": "Illuminate\\Http\\Resources\\Json\\{closure}",
"class": "Illuminate\\Http\\Resources\\Json\\PaginatedResourceResponse",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Support/Collection.php",
"line": 638,
"function": "array_map"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php",
"line": 23,
"function": "map",
"class": "Illuminate\\Support\\Collection",
"type": "->"
},
This is what causes the error:
$products = Product::findMany($array)->paginate(10);
//dump($products);
/*Create ResourceCollection*/
return new ProductResourceCollection($products);
The dump returns this:
------------ -----------------------------------------------
date Thu, 16 Apr 2020 08:53:53 +0000
controller "ProductApiController"
source ProductApiController.php on line 56
file app/Http/Controllers/ProductApiController.php
------------ -----------------------------------------------
Illuminate\Pagination\LengthAwarePaginator^ {#300
#total: 1
#lastPage: 1
#items: Illuminate\Database\Eloquent\Collection^ {#319
#items: array:1 [
0 => App\Product^ {#400
#casts: array:9 [
"category" => "object"
]
#connection: null
#table: "products"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:21 [
"id" => "1"
"title" => "Test"
"category" => "{"id":1,"title":"Test","slug":null}"
]
#original: array:21 [
"id" => "1"
"title" => "Test"
"category" => "{"id":1,"title":"Test","slug":null}"
]
}
]
}
#perPage: 10
#currentPage: 1
#path: "http://example.org/api/product/pluck/1,2,3"
#query: []
#fragment: null
#pageName: "page"
+onEachSide: 3
#options: array:2 [
"path" => "http://example.org/api/product/pluck/1,2,3"
"pageName" => "page"
]
}
This is the resource:
public function toArray($request)
{
return [
'current_page' => $this->resource->currentPage(),
'first_page_url' => $this->resource->url(1),
'from' => $this->resource->firstItem(),
'last_page' => $this->resource->lastPage(),
'last_page_url' => $this->resource->url($this->lastPage()),
'next_page_url' => $this->resource->nextPageUrl(),
'per_page' => $this->resource->perPage(),
'prev_page_url' => $this->resource->previousPageUrl(),
'to' => $this->resource->lastItem(),
'total' => $this->resource->total(),
'data' => $this->collection->transform(function ($product
) {
return [
'id' => $product->id,
'title' => $product->title,
'category' => $product->category,
];
}),
];
}
If I comment 'data'=> $this->collection->transform(function ($product) { the error does not appear... But... Well, then the app does not work ;-)
My question
So my question is: Is this way of modifying data incorrect and how can I fix this?
The problem is caused by https://github.com/laravel/framework/pull/32296 .
At the moment I can do something like
$this->collectResource($this->collection)
->transform(...)
which solves the problem.

How to check tags uniqueness of tags using spatie/laravel-tags plugin

Using spatie/laravel-tags plugin in my Laravel 5.7 app.
I make editor of tags, so that admin would be able to add tags . However, I need to make validation on tags uniqueness.
Usual validation rules like
'name' => [
'required',
'string',
'max:255',
Rule::unique(with(new Tag)->getTableName())->ignore($tag_id),
],
'order_column' => 'nullable|integer',
does not work here, as fields are in json format like:
{"en": "Drama"}
Could you, please, give a hint in which way this validation can be done?
MODIFIED BLOCK # 2
In my request app/Http/Requests/TagRequest.php I wrote validation rules:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use App\Rules\TagUniqueness;
class TagRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
// $request= Request();
return [
'name' => [
'required',
'string',
'max:255',
new TagUniqueness,
],
'order_column' => 'nullable|integer',
];
}
}
and created rule app/Rules/TagUniqueness.php has:
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class TagUniqueness implements Rule
{
public function __construct()
{
$this->d( '<pre>TagUniqueness $_REQUEST::' . print_r( $_REQUEST, true ) );
}
public function passes($attribute, $value)
{
$this->d( '<pre>passes $attribute::' . print_r( $attribute, true ) );
$this->d( '<pre>passes $value::' . print_r( $value, true ) );
return false;
}
...
and I recieved this error:
"message": "trim() expects parameter 1 to be string, object given",
"exception": "ErrorException",
"file": "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php",
"line": 217,
"trace": [
{
"function": "handleError",
"class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
"type": "->"
},
{
"file": "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php",
"line": 217,
"function": "trim"
},
{
"file": "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php",
"line": 199,
"function": "parseArrayRule",
"class": "Illuminate\\Validation\\ValidationRuleParser",
"type": "::"
},
{
"file": "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/proengsoft/laravel-jsvalidation/src/Remote/Validator.php",
"line": 161,
"function": "parse",
"class": "Illuminate\\Validation\\ValidationRuleParser",
"type": "::"
},
{
"file": "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/proengsoft/laravel-jsvalidation/src/Remote/Validator.php",
"line": 144,
"function": "purgeNonRemoteRules",
"class": "Proengsoft\\JsValidation\\Remote\\Validator",
"type": "->"
},
{
"file": "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/proengsoft/laravel-jsvalidation/src/Remote/Validator.php",
"line": 116,
"function": "setRemoteValidation",
"class": "Proengsoft\\JsValidation\\Remote\\Validator",
"type": "->"
},
{
as $this->d( my debugging method, I see output of TagUniqueness' s constructer, but passes method IS NOT CALLED and I can not define the reason of this error.
What is wrong?
Thanks!

Resources