Interview Q&A · questions with model answers
Laravel Interview Questions
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Which Artisan commands would you run when deploying Laravel to production, and why?
Cache the configuration, routes, events and views (php artisan optimize), run migrations with --force, and restart queue workers with queue:restart so they load the new code.
-
Most asked Gates or policies: how does authorization work in Laravel?
Gates are closures for actions not tied to a model (viewAdminDashboard); policies are classes that group authorization for one model (OrderPolicy::update($user, $order)). Both are checked with can,…
-
Most asked Eloquent or the query builder: when do you use which?
Eloquent is the ActiveRecord ORM: models, relationships, events, casts and accessors. The query builder builds SQL fluently and returns plain objects. Both use PDO with bound parameters.
-
Most asked Sanctum or Passport: which do you choose for API authentication?
Sanctum for first-party SPAs (cookie sessions with CSRF protection) and simple API tokens for mobile apps or integrations; Passport when you need a full OAuth2 server for third-party clients.
-
What is the difference between the register and boot methods of a service provider?
register should only bind things into the container; boot runs after every provider has been registered, so it can safely use other services (routes, events, view composers, macros).
-
Which Eloquent operations do not fire model events, and why does it matter?
Bulk operations that run one SQL statement without loading models: Model::where(...)->update(), ->delete(), insert(), upsert(), and DB::table() queries. Observers, mutators, $touches and soft-delete…
-
What is the difference between hashing and encryption in Laravel, and which do you use when?
Hashing (Hash::make, bcrypt or Argon2) is one-way and is for passwords; you can only check a value against it. Encryption (Crypt::encryptString, the encrypted cast) is reversible with APP_KEY and is…
-
Pest or PHPUnit for Laravel tests?
Pest is built on PHPUnit with a terser functional syntax (it('...', fn () => ...), expect()), datasets, architecture tests and parallel runs. PHPUnit classes still run under Pest, so the choice is…
-
Livewire or Inertia: how do you choose a front-end approach for Laravel?
Livewire builds reactive UIs in PHP and Blade: components re-render on the server and the page is patched over AJAX. Inertia keeps server-side routing and controllers but renders pages with React,…