Laravel Flashcards
Learn Laravel inside-out
Write the simplest “Hello World” route.
Route::get(‘/’, function () {
return ‘Hello, World!’;
});
All of the configuration files for the Laravel framework are stored in…
The config directory.
How to override configuration values when running tests?
Create a .env.testing file. This overrides .env when running PHPUnit or executing Artisan commands with the –env=testing option.
How to retrieve environment variables from within config files?
Use the env helper.
‘debug’ => end(‘APP_DEBUG’, false);
Second argument is the default fallback.
Only call this within config files because once the configuration has been cached (php artisan config:cache) all calls to env() will return null.
How to determine the current environment? (dev/production etc)
Using the App facade, App::environment() returns the APP_ENV value from the .env file.
What does the App::environment method do?
Returns the APP_ENV value from the .env file. Pass it a string and it returns boolean if the env matches.
App::environment(‘local’); //true if in local
App::environment([‘local’, ‘dev’]); //true if in local OR dev
How to access configuration values (globally)?
Use the config helper function. Use dot-syntax of filename.option, eg:
$value = config(‘app.timezone’);
How to set configuration values at runtime?
Pass an array to the config helper:
config([app.timezone’ => ‘America/Chicago’]);
How to put an application into maintenance mode? and to disable maintenance mode?
php artisan down
php artisan up
What happens when a request is made and the application is in maintenance mode?
A MaintenanceModeException is thrown with status code 503 (service unavailable).
Where to customize the default maintenance mode template?
resources/views/errors/503.blade.php
How to generate a model in a ‘App/Models’ folder, and not in the default App folder?
php artisan make:model Models/Car
What does the bootstrap directory contain?
The app.php file which bootstraps the framework.
Also, a cache directory of cached files (eg routes and services)
What does the config directory contain?
All the applications configuration files.
What does the database directory contain?
Migrations, model factories, and seeds.
What does the public directory contain?
index.php - the entry point for all requests.
Also houses compiled assets such as JS and CSS.
What does the resources directory contain?
All views and un-compiled assets such as SASS and JS. Also language files.
What does the routes directory contain?
The route definitions: web, api, console and channels.
What does routes/web.php do?
Contains your web routes that the RouteServiceProvider places in the web middleware group, which provides session state, CSRF protection, and cookie encryption.
What does routes/api.php do?
Contains your API routes that the RouteServiceProvider places in the api middleware group, which provides rate limiting. These routes are stateless, so should be authenticated via tokens and will not have access to session.
What does routes/console.php do?
Contains your closure-based console commands.
What does routes/channels.php do?
Where you register all of the event broadcasting channels that your application supports.
What does the storage directory contain?
app directory to store application-generated files.
framework directory to store framework-generated files.
logs directory contains application’s log files.
storage/app/public to store user-generated files (is symbolically linked in public/storage)
What does the tests directory contain?
Feature and unit tests