Mohamed Ashraf
Mohamed Ashraf

Reputation: 41

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

Upvotes: 4

Views: 13179

Answers (4)

Hung Pham
Hung Pham

Reputation: 223

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

Upvotes: 1

albus_severus
albus_severus

Reputation: 3702

use postman https://www.getpostman.com/downloads/ it's an excellent thing very much usefull

Upvotes: 0

Paladin
Paladin

Reputation: 1637

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

Upvotes: 3

neha gupta
neha gupta

Reputation: 30

You can use logging feature of Laravel. Apply Logs on entry point of application to test whether API url is hitting or not.

Upvotes: 0

Related Questions