Laravel Flashcards
How do you create a laravel project?
laravel new dev.todoparrot.com
In the laravel project folder, what is the .env file for?
Managing settings to do with the project, such as database passwords etc.
What does the .gitattributes file do?
Used to maintain consistent settings across machines
What does .gitignore do?
Tells git which files to ignore from the repository
What is in the app directory?
Most of the custom code written for the project
What is the artisan command in the root directory?
A command line configuration tool
What is the bootstrap directory?
All the code required to initialise and start up the laravel application
What is in the config directory?
Mainly basic configuration files and things like database credentials, cache and email settings
What is gulpfile.js?
Used as part of elixir, it is used to automate compilation of css and js files.
What is package.json?
Used by elixir to install elixir and it’s various dependencies.
What is phpspec.yml?
Used to configure the behavior driven tool PHPSpec (I believe testing)
What is phpunit.xml?
PHPUnits configuration file for laravel.
What is the public directory?
The root directory of the application.
What is the other term for the index.php file in the public folder?
The frontcontroller.
What is in the resources folder?
Projects views and localised language files. You can also store your raw resources here such as coffee script etc.
What is the vendor folder for?
That is where the laravel and other related code is stored (via composer).
How do you start the built in laravel server?
php artisan serve
How do you set the namespace for your new laravel app?
php artisan app:name myprojectname
When setting a new namespace using the artisan command, what is updated?
All controllers / models any other relevant files as well as the composer.json file (psr-4 settings for autoloading)
The app.php file is in the config directory, what does it contain?
App wide settings including things like debug information.
The auth.php file is in the config directory, what does it contain?
Settings specific to authentication, including which model manages users, how password reminders are managed, database tables containing user information.
The broadcasting.php file is in the config directory, what does it contain?
Contains information pertaining to the way laravels new broadcast feature operates.
The cache.php file is in the config directory, what does it contain?
Contains configuration information for different caching modules.
The compile.php file is in the config directory, what does it contain?
Laravel can improve performance by generating a series of files that allow for faster package loading - this file allows you define which classes should be added and included in the final optimisation step.
The database.php file is in the config directory, what does it contain?
Database authorisation credentials as well as the database module it will support.
The filesystems.php file is in the config directory, what does it contain?
The configuration file defines the different file systems the project will handle for file uploads. Could be localdisk, amazon s3 or rackspace.
The mail.php file is in the config directory, what does it contain?
Various settings for sending mail in php.
The queue.php file is in the config directory, what does it contain?
Queues can improve performance by offloading certain tasks to queueing solutions such as beanstalk and Amazon Simple Queue Service.
The services.php file is in the config directory, what does it contain?
If your application uses any third party services such as stripe, this file will allow configuration of those files.
The session.php file is in the config directory, what does it contain?
You can use a number of different session management services such as filesystem, cookies, database - configure the options here…
The view.php file is in the config directory, what does it contain?
Configure the location for the templates for the views and renderer used for pagination.
Laravel refers to the development environment as what?
local environment
Settings in the .env file can be retrieved by using which function?
env()
What builtin function can be used to print debug information about arrays / objects etc?
dd()
Where is the default location for laravel to store logs?
storage/logs/laravel.log
What 3rd party app manages laravels logging?
monolog
How would you write to the log in laravel?
\Log::debug($item);
$item could be a string, or array what ever.
How do you specify the logging severity?
\Log::warning($item);
\Log::info($item);
\Log::error($item);
\Log::critical($item);
How can you get debug information to appear in a firefox window/
You need to install firebug, and FirePHP extension
You trigger it through monolog->pushHandler
How do you perform interactive debugging in Laravel?
Use tinker
php artisan tinker –env=local
Once you’ve added a new package (such as debugbar) to the vendors directory via composer, how do you install it?
You need to add an entry in the config/app.php for both the aliases and providers array.
Then you must run the following command:
php artisan vendor:publish
How do you render a message to the debug bar?
\Debugbar::error(‘Something is definitely going wrong’);
How can you make a composer package globally available?
Use the command
composer global
There is an issue with Laravel 5.1 and the “laravel new” command, what is it?
It doesn’t simlink the phpspec or phpunit files - causing an error message.
If you place a view in a subfolder of the view directory, how do you reference this in code?
Use dot notation. return view('home.welcome'); This will access a file called welcome.blade.php in the home directory which is in the base view directory.
How do you make a new controller in laravel?
php artisan make:controller –plain NameOfController
What happens if you ommit the –plain flag when using artisan to create a controller?
Laravel will create a controller containing stubs for a RESTful controller.
If you use “php artisan make:controller” to make a new controller, where is it created?
app/Http/Controllers/NameOfController.php
In the laravel community, a RESTful controller is often referred to as…
Resource Controller
It is common to associate one controller with one what?
Resource - i.e. ListsController will only get a ‘list’ or set of ‘lists’.
How would you get a list of all available routes?
php artisan route:list
How do you cache your routes?
php artisan route:cache
If you add, edit or delete a route after caching your routes, what must you do?
either clear or rebuild the routes
route: clear
route: cache
What must be present in a view filename so that laravel recognises it as a blade augmented file?
.blade.php
Passing multiple variables into the view function can be messy, how can we simplify this?
Use the PHP function compact: $name = "foobar"; $date = date('Y-m-d'); return view('home.welcome', compact('name', 'date'));
How could you use a default value in a blade, if the wanted variable was not set?
welcome {{ $name or ‘superman’ }}
In laravel 5 there was a change to the way output is escaped in a blade template, how is it done now (used to be {{{ }}} - triple braces)?
{!! ‘my list alert(‘go fuck yourself’)’ !!}
What is the loop syntax in a blade template?
@foreach ($lists as $list)
{{ $list }}
@endforeach
What can you do to mitigate risk of an array being empty in a blade template?
Use a forelse loop
@forelse ($lists as $list) {{ $list }} @empty "You don't have anything in that list!" @endforelse
How can we test if an array is full / empty?
@if(count($lists) > 0) // Do something @else // Do something else @endif
What is the else-elseif-else syntax?
@if (count($lists) > 0) // Do stuff @elseif (count($lists) == 1) // Do otherstuff @else // Do yet more stuff if the otherstuff didn't pan out @endif
What is the ‘blade’ methodology for dealing with templates (such as header/footer etc)?
Using what is called a “master layout”.
What blade function to we use to tell the blade system what to place in a section of the template?
@yield(‘content’)
When building a blade that should use a master layout, how do you tell the system which layout to use
@extends(‘layout.master’)
Assuming there is a folder called layout with a blade called master in it
In the layout - we use the function ‘yield’, and pass it the name of the section that should go here. How do identify this section in the blade file that is using the master layout?
@section(‘content’)
// Put stuff in here.
@endsection
What is the purpose of the @section / @show combination (in the master layout)?
@section(‘title’);
Laravel
@show
This can be used to append content from a page, using the @parent call
@section(‘title’)
@parent
:: some page
@stop
Would give you in the output
Laravel :: some page
How could you have default content in a blade?
One of two ways - use the @section @show combination. It sets up a section, and yields it straight away.
Or use @section(‘section’, ‘default value’)
If you wanted to remove the parent templates html in a particular section, how would you change the following code? @section('title') @parent :: some page @stop
Simply remove the @parent directive
@section(‘title’)
:: some page
@stop
How would you make the following code prepend the template data, rather than append?
@section(‘title’)
@parent
:: some page
@stop
Change the location of the @parent call
@section(‘title’)
:: some page
@parent
@stop
What is the laravel name for the concept of managing smaller components (i.e. widgets) for a webpage, but in it’s own template?
view partials
Images, CSS and JS should be placed where?
The public directory of the app (root folder contains the public folder)
How do you reference HTML and JS files?
You can use standard HTML, or you can use the facade. However, you have to include the facade as it’s not a standard part of Laravel anymore. “LaravelCollective/HTML”
Syntax
{!! HTML::image(‘images/logo.png’, ‘todoparrot logo’); !!}
What are the two best ways to test customer interaction of a web page? (I.e. if I click on this link, do I get the expected page?)
You can use one of two packages - the built in (as of laravel 5.1) HTTP request API, or you can use a third party composer package called Goutte, which contains a web crawler that can determine if links exist.
What does the ‘fetch’ field mean in the laravel config/databases file?
It specifies how Eloquent will retrieve SQL data. By default it retrieves data in PHP stdClass format.
How do you create a model?
php artisan make:model Todolist
How do you crate a migration?
When using make:model - you can supply the -m switch.
php artisan make:model Todolist -m
Otherwise:
php artisan make:migration create_todolist_table