Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 870
Mohamed Ashraf Avatar asked Oct 19 '25 17:10

Mohamed Ashraf


2 Answers

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

like image 196
Paladin Avatar answered Oct 21 '25 07:10

Paladin


This is my way, but I think it's not good!

  1. 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');
  1. Create a post by form or ajax in one resource/view like index
  2. Go to page, and debug with phpstorm
like image 26
Hung Pham Avatar answered Oct 21 '25 08:10

Hung Pham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!