Postman not Working with Laravel Valet (Local) - laravel

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.

Related

Local url [app_url] not working in Laravel Breeze Vue

So I tried creating a new project using Breeze+vue in Laravel.
I was following this guide: https://www.youtube.com/watch?v=A7UlfXPhsaA
When I finally got vite running on npm run dev without issues, I came across the app_url and I tried to change it to something similar like in that guide (timestamp 6:14 in video), in my case the app_url value was just http://localhost and I changed it to http://grandia.test.
And it reflects like that when vite is running:
VITE v3.1.0 ready in 1031 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
LARAVEL v9.28.0 plugin v0.6.0
➜ APP_URL: http://grandia.test
but nothing happens when I go to the site. only the localhost:5173 works properly.
I tried googling for answers but I couldn't find anything helpful.
Could someone help me out what I'm doing wrong or missing? Thanks!
I had the same issue, It look like you changed URL: http://grandia.test instead of localhost. So you should try with npm run build instead.
Changing Laravel’s APP_URL parameter will not magically allow you to choose the URL your website is served at. It will only tell Laravel what it should use when generating URLs related to your website.
The video’s author uses the Laravel Valet local development environment. It provides a park command that allows you to automatically serve the subfolders of some folder (e.g. Sites in the video) at http://<subfolder>.test.
In the video, the project is created in Sites/reddit-clone/, which makes it possible to directly access it at reddit-clone.test.

how to debug during API with laravel

I run my laravel app #localhost.
```php artisan serve --host=localhostIP```
On top I run an Andoid app with the same base URL.
Could anyone tell me how can I debug incoming API´s calls
like if BASEURL/users is called?
Furthermore, how can I log the happening events in the console
I am developing API's with laravel too, i do it this way:
composer require laravel/homestead to have it all in a vm 😉 see https://laravel.com/docs/master/homestead for more information, i use the "per project" installation
Download postman to have the best tool for sending querys to your api and to test your api quick -> https://www.getpostman.com (i use it free)
configure and run your homestead (it's not that complicated).
your homestead is fit with php and xdebug enabled
i am using phpStorm and have my vagrant setup as deployment target
"listen to debug" with phpstorm
to your GET requests, add a queryparam XDEBUG_SESSION_START=PHPSTORM
i can debug my api now 😉
i also wrote https://logcrawler.de to receive the log informations of all my api's and all my server 🤩
I hope, i could help you a little bit
This is my way, but I think it's not good!
Create router api in config/web, Eg:
router/api: Route::post('/check_api', [CheckController::class, 'testFunc'])->name('api.check_api');
web/api: Route::post('test/check_api', [CheckController::class, 'testFunc'])->name('test.check_api');
Create a post by form or ajax in one resource/view like index
Go to page, and debug with phpstorm
You can use logging feature of Laravel. Apply Logs on entry point of application to test whether API url is hitting or not.
use postman
https://www.getpostman.com/downloads/
it's an excellent thing very much usefull

Not working on Laravel Controller, Working on Tinker

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.

intervention-image with laravel 5.2 on ubuntu-server breaks the other calls

I am using laravel 5.2 to write services for a mobile app. all the calls are working fine. My project is deployed in ubuntu server.
Now I want to resize the uploaded images inorder to maintain same performance. I thought of trying intervention-image.
In local machine it worked fine. I installed intervention-image and set the provider and alias name, I included the alias name to controller. Once I do that and update the server, all the other calls are getting effected. I am getting 505 error.
It's the intervension-image which is causing this problem, I checked with previous upload and I am getting all the calls. Any suggestions?
I suggest you create a dev environment like your production , use vagrant . About error 505 check you error log file to have more detail about the bug

Hosting a laravel application

I'm new here. I've tried all I could but couldn't setup my laravel app. I've also tried the solutions provided here
How to install Laravel 4 to a web host subfolder without publicly exposing /app/ folder?
but I keep on getting HTTP Error 500.0 - Internal Server Error The page cannot be displayed because an internal server error has occurred.Any help please?
change your host php version
PHP >= 5.4
MCrypt PHP Extension
http://laravel.com/docs/4.2#server-requirements
Consider using Forge, it saves you a lot of time and you would support the creator

Resources