Laravel

Laravel Packages

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

20 câu hỏi phỏng vấn·
Senior
1

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

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Laravel cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí