Laravel

Laravel Packages

Package development, service providers, facades, publishable assets, configuration, migrations, package discovery

20 domande da colloquioยท
Senior
1

What is the main difference between the register() and boot() methods of a Service Provider?

Risposta

The register() method is used to bind services to the IoC container without depending on other services, as they are not yet available. The boot() method is called after all providers have been registered, allowing access to all registered services and configuration of features that depend on them such as routes, views, or events.

2

What is the recommended basic structure for a Laravel package?

Risposta

A well-structured Laravel package contains a src/ directory for PHP source code including the Service Provider, a config/ directory for configuration files, a composer.json with metadata and PSR-4 autoload, plus optional directories for resources like database/, resources/, and routes/. This organization facilitates maintenance and follows community conventions.

3

How does package discovery work in Laravel?

Risposta

Package discovery uses the extra.laravel section in the package's composer.json to automatically declare providers and aliases. During installation via Composer, Laravel reads this metadata and automatically registers services without manual modification of config/app.php. This feature simplifies package installation and reduces configuration errors.

4

How to make a configuration file publishable in a Laravel package?

5

What is the purpose of the mergeConfigFrom() method in a package Service Provider?

+17 domande da colloquio

Padroneggia Laravel per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis