0

I'm a JavaScript developer and for server side I always do Node/Express. Now I'm learning to use Laravel but I'm running some confusions about callback concept.

For exemple: In Express when I do app.get('/myroute', function(req, res){...}) , the function(req, res) part is callback that will run after the serve receives the get request. In Laravel I have have something similar when using the routing system like when I do Route::get('/myroute', function(){...}) - I understand that the static method get of the Route class is executed but the function(){...} at the second parameter. So is that function also called "callback" like it the case for JavaScript? Is the event concept the same for the 2 programming languages?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Christian LSANGOLA
  • 2,947
  • 4
  • 22
  • 36
  • 1
    Sure. You can call it a callback. PHP doesn't have events as is. To be able to use events, you need to have a library (or write your own) that handles that. Then it's up to the implementation to decide how it works. – M. Eriksson Jan 24 '19 at 08:48

2 Answers2

0

The anonymous function in the Route::get('/myroute',function(){...}) is indeed a callback. PHP also calls those callables.

The event concept may or may not be used on either language. It's all about the context of each situation. This is true because callbacks can be used with our without the need of having an event.

Sotiris.k
  • 1
  • 1
  • 2
0

Callback concept is the same in all programming language. Executing a function a get the return response as a parameter in your callback. What is a callback function?

Pascal Tovohery
  • 888
  • 7
  • 19