Not working on Laravel Controller, Working on Tinker - laravel

Guzzle version(s) affected: 6.3 Laravel: 5.6.3 PHP: 7.2.10
Description
If I am trying to get response in tinker
$client = new \GuzzleHttp\Client();
$response = $client->get($url);
json_decode($response->getBody())
I am getting response as expected.
but in my controller
$object_res = $client->get($url);
I am getting error
"cURL error 3: malformed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)",…}
Which means, the url is incorrect, but as I have described, this working perfectly in tinker.
Note
I am getting everything working perfectly in my localhost, this is occurring only on my test server.
Please let me know, if I need to give additional information.

Tinker uses a different runtime than your application, this could be causing an issue because in one scenario. php goes directly from your box to the api server and in the other it goes through your webserver before making the request.
The first thing to do would be to clear your laravel cache and config with
php artisan cache:clear
and
php artisan config:clear
if that fails I would look into the cross-domain restrictions or settings on your web server.

Please check for Guzzle requirements on your server. specially
To use the PHP stream handler, allow_url_fopen must be enabled in your system's php.ini.

I just ran into this problem on my testing server, I found it using cockpit. but my problem was with alouy/youtube. check selinux if you have that on your production server. check file permission of .env too. Hard to give a solution when the variables of your server are not presented.
also Read your laravel logs, that presented the solution to me.
hope this helps.

Related

ErrorException - Trying to access array offset on value of type null in ServiceProvider.php line 84 in Lumen

I am new to Lumen so I just downloaded and installed a fresh lumen setup but unfortunately as soon as I hit postman it sends me above error. I have read many posts all says to use isset() i did so but still error persists therefore i request to help me.
Composer update also does not work.
Thanks!
It seems to be an issue between your version of PHP and Lumen 5.*
I found something here https://github.com/DarkaOnLine/SwaggerLume/issues/82
This worked for me
// in bootstrap/app.php
$app->configure('view');

unserialize(): Error at offset 0 of 40 bytes

This Error comes When i try to server site login.
How to solve this error?
You have to set a news Key, use the following command:
php artisan key:generate
After that test again to run the Laravel Application
php artisan serve
See the similiar question: unserialize(): Error at offset 0 of 40 bytes Error
Laravel made a change to the way it handles cookies from V5.6.30 to improve security. It may be that you are trying to decrypt something that isn't serialized or vice versa.
First, Delete the cookies in your browser and/or clear your session-files in your Laravel app.
Or, within the middleware app\Http\Middleware\EncryptCookies.php, you can flip it to test:
add: protected static $serialize = true;
This is a pretty common question - you can search stack overflow for similar answers if this doesn't work.
Delete the cookies in your browser and/or clear your session-files in your Laravel app.
I got the same error, when I upgrade a Laravel 5.5 app to 5.6. The error comes form the EncryptCookies-Middleware.
This type of issue normally rise when you downgrade your Laravel version and a quick solution is I just clear my laravel and browser cache and it will work fine for me. Browser cache clear is mostly important.

Postman not Working with Laravel Valet (Local)

When I use Postman to send or get data to/from my local Laravel applications it always returns the error...
Could not get any response.
For example, a GET request to
http://demo_app.localhost/api/data.
I use Laravel Valet on my Mac. It looks like Postman can't find the local domain.
I had the same issue when trying to use valet with Postman and what fixed it for me was turning off the SSL verification in Settings > General. I believe valet is using some internal SSL certificate by default that cannot be verified properly by Postman.
Use TLD .test, if your Valet version is up-to-date and not specifically configured to use .localhost.
Should be like http://demo_app.test/api/data
See official docs for background:
Valet documentation at chapter "Using Another Domain".
I had the same issue and used all the suggestion above, none of them works.
For my case, I used the following command to fix the problem:
php artisan optimize
This clears the cache and config files and reloads the new api Routes added to the Laravel framework.

Laravel artisan command from controller

I update my .env file using a function in my controller.
After I save the settings I need to update, I call Artisan::call('config:cache') to clear the cache of my site's configuration.
Everything works fine on localhost, but when I try to clear config cache on production, it doesn't work. (No warnings or errors.)
I even tried with --no-interaction option attached to this CLI command.
Did anyone have this problem and know what causes it?
check into the PHP security settings and make sure you can run these exec,passthru,shell_exec functions in your server.

Getting strange errors installing a Laravel application

The first problem I'm running in to is that when installing I receive a mysql error stating that a table cannot be found. Of course it can't, I finished installing the dependencies much less run the migration. The error was being triggered by a Eloquent query in a view composer. After commenting out the entirety of my routes file Composer let me continue.
I proceed to uncomment out my route file - I get the error once again trying to run any artisan commands (can't migrate my database because I haven't migrated my database). Repeat the solution for step one and I've migrated my database.
Artisan serve is now serving me my layout file in the terminal and exiting. I'm at a bit of a loss to troubleshoot this. I assumed that it was possibly a plugin, trying to disable plugins one by one results in:
Script php artisan clear-compiled handling the pre-update-cmd event returned with an error
and being served up my layout file in the terminal.
It seems that the error is directly related to this function in my routes file:
View::composer('layouts.main', function($view) {
$things = Thing::where('stuff', 1)->orderBy('stuff')->get();
$view->with(compact('things'));
});
This isn't a new introduction to the application however so the underlying cause is coming from somewhere else.
As i said in the comment, if you are finding database errors in production server but not in local, then
check database credentials. if its ok then....
check the different configs in the environment.
using profilers(any) will let you know what environment you are in.

Resources