Laravel Flashcards

1
Q

What are route requests?
Route :: get(‘/’, function () {
return view(‘welcome’);
});

A

Declaring a route that listens for a get request and a get request is just visiting a URL in the browser. The forward slash in the code above means the request is for the Home page. If we wanted to view the about page, we would add the appropriate directory, example ‘/about’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is blade.php?

A

Blade is Laravel’s templating engine, a layer on top of php that offers a few useful bells and whistles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are routes and views related?

A

You can visit the routes file, you can declare routes, and that route can return what we refer to as a view. A view is the markup in the template for what the user views.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Components directory?

A

Any kind of reusable block that could be referenced in multiple places around your application - a task, a menu, a drop down item, a layout file, a card, a message, an avatar etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a layout file?

A

A layout is a component. When we create a layout file within the Components directory, it’s a signal to Laravel that it should be treated as a component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you reference a components file such as the layout file?

A

We always start components with x- to make sure that they are unique and they don’t interfere with existing html tags, and then we reference the name of the component. Write it just like a simple html tag.

<x-layout>
</x-layout>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the variable name called slot?

A

$slot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are master files?

A

We’ve created a new component for a layout file. Some refer to these as Master files. The layout file is almost like the structure for your application. head tag, any scripts or stylesheets you need to import, nav, footer. And then the main section will always be unique for each page so we will define the structure and then we will slot in any page specific markup.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does blade replace variables like slots <?php echo $slot ?> ?

A

{{ $slot }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does blade relate to vanilla php?

A

Behind the scenes, your blade code is being compiled to vanilla php.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are these called? {{ }}

A

A shortcut blade uses to compile it to a php echo.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Tailwind CSS?

A

A CSS utility framework - you can declare classes that refer to specific CSS properties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is PHP?

A

Hypertext Preprocessor. A popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic. PHP is an open-source, server-side programming language that can be used to create websites, applications, customer relationship management systems and more. It is a widely-used general-purpose language that can be embedded into HTML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s a prop?

A

A prop is a custom attribute in php

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What levels of colors are used in Tailwind?

A

Level 100 is the lightest, Level 900 is the darkest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a URI?

A

Uniform Resource Identifier - is a sequence of characters that distinguishes one resource from another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are blade directives?

A

They start with the @ symbol. Short hand that compile down to vanilla php echo statements or function calls.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What do braces represent in Laravel?

A

Braces indicate that whatever is wrapped inside is a wildcard - it contains it to pass to the function so we can use it however we want.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What’s a dd function?

A

Dump and die. Dump the id and then kill the execution.

19
Q

What is an Arr class in Laravel?

A

An array

20
Q

What does MVC mean?

A

MVC stands for Model-View-Controller. It’s not unique to Laravel. Other frameworks like CodeIgniter, Ruby on Rails, Django, Backbone.js, Ember, and Spring adhere to it. It’s a system for how to go about constructing applications and how each piece of the puzzle can and should communicate with each other. Views are the presentation layer. Controllers are defining a route and having a function to handle the route. Your model can represent your data persistence but also the business logic tier of your application.

21
Q

What is a namespace?

A

Simply, a namespace is a way to organize your code so the directory references the specific file you’re working in and not another with the same name in a different folder.

22
Q

What is psr-4 in the composer.json file?

A

It’s a standard and convention for autoloading files and we can define our mapping there and Laravel does that for you automatically.

23
Q

What is your .env file?

A

This contains all your various preferences, passwords, and strings for your projects including the database you want to use, is your application currently in a debug state – if you’re working locally then this will be true, if you push it live, then that value will be set to false. If you’re connecting to any APIs and you can include the API keys here. This stores any potentially sensitive info that prevents it from being shared in github and such because this file is included in .gitignore.

24
Q

What is the output from running php artisan in your Herd/example folder?

A

You will see a list of commands sorted according to a namespace.

25
Q

What are migrations?

A

We use a migration class to define the initial structure of that table, we ran the migration by running php artisan migrate from the command line. Fetch the data from the database and then render it in the View.

26
Q

When can you run the migrate:refresh command?

A

Never run migrate:refresh in a production site because it will erase everything in the database.

27
Q

What is SQL?

A

Structured Query Language. Is the gold standard language for communicating with Relational Database Management Systems (RDMS). Databases like MySQL, Postgress, Microsoft Sql Server, Oracle - they are all based on SQL with their own little variations. It’s a collection of clauses that make up an SQL statement.

28
Q

What is SQLite?

A

SQLite is a software library that provides a relational database management system (RDBMS) based on SQL. It’s not universally applicable but it’s a small database engine that’s easy to embed into applications - used as an in-memory database. It’s a good light-weight utility database for prototyping things. It’s just a flat file, read-only storage, embedded situations, mobile applications. It’s not good for multiple writers, not good for extremely large databases (like amazon or google - multi million rows).

29
Q

What is Eloquent in Laravel?

A

It is an ORM - Object Relational Mapper. An ORM maps an object in your database like a table row to an object in your php code. This is Laravel’s active record implementation. Convert your php to an eloquent model so that it can pull the info from the database!

We’re no longer hard-coding arrays, it’s just pulling from the database! Use eloquent to insert and delete records from the database!

29
Q

What is the factories category used for?

A

Use a model factory to quickly scaffold example data.

30
Q

What does the command php artisan tinker do?

A

Your command line playground for your laravel app. Does it work the way I expect it to? Manipulate variables to see if it returns what you expect!

30
Q

How do you convert your php to an eloquent model?

A

extends Model and use Illuminate\Database\Eloquent\Model

30
Q

Rule number 1 when dealing with users sending in form requests? How do you prevent them from overwriting items?

A

You have to assume they are malicious and trying to do something wrong. Add a protected $fillable property – this represents all of the values that are allowed to be mass assigned.

31
Q

What is IDE?

A

Integrated development environment

32
Q

What are Model Factories?

A

They are excellent for scaffolding data for your local environment and for the purposed of preparing a test.

33
Q

Simple explanation of Database Relationships in the jobs listing project example?

A

We set it up so that a job listing belongs to a corresponding employer.

34
Q

If we have the job object, how we fetch the name of the employer that gave us the listing?

A
35
Q

Eloquent Relationships

A
36
Q

What is lazy loading?

A

Lazy loading refers to the delay of an SQL query until the last possible moment.

37
Q

What is an Eloquent Collection?

A

An array on steroids haha.

38
Q

How do we access the first job?

A

Interact with it like an array
$employer->jobs[0]
or a collection
$employer->jobs->first()

39
Q

What’s the relationship between a Post and a Comment in a blog?

A

A Post can have many Comments so you use the hasMany() method.

40
Q

What’s the relationship between a Comment and a Post in a blog?

A

A Comment belongs to a Post so you use belongsTo() method.

41
Q

What’s the relationship between a Post and a User in a blog?

A

A Post belongs to a User so you use belongsTo()

42
Q

What’s the relationship between a Post and Tags in a blog?

A

A Post can have many Tags so you use hasMany() method. Actually no lol. Go to Day 12 Laravel for the answer haha

43
Q
A