Technically, they are completely different. View::share simply sets the variable, and View::composer is a callback function.
Let me explain in more detail:
View::share really straightforwardly sets a variable that can be used in any of the views, think of it as a global variable.
View::composer logs an event that is raised when a view is rendered, do not confuse it with View::creator , which is fired when an instance is created.
View::composer / View::creator can be used as a class that is well documented .
Although they give you the ability to pass additional data into the view, they also give you the ability to do many other things, for example, they could:
- Help debugging a view
- Register viewing information
- Use to create custom caching (maybe this is not a good idea, but possible)
These are just some examples of what could be used with View::composer and View::creator .
source share