Laravel 8 from scratch Flashcards

1
Q

how do you start a laravel server with artisan

A

php artisan serve

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

what function do we use to render a 404 page?

A

abort();

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

how to cache in a route?

A

cache()->remember(unique name , seconds (now()->addHour()) , closure)

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

what do we return if we cannot find a model?

A

new modelNotFoundException();

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

what PHP function do we use to return an array from another array?

A

array_map();

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

what wrapper do we use in laravel for PHP arrays?

A

a collection

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

how do we echo something in blade?

A

{{ }}

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

how to echo un-escaped HTML in blade?

A

{!! !!}

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

how to write a foreach in blade?

A

@foreach @endforeach

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

how to dd in blade template?

A

@dd();

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

how to add conditional to blade template?

A

@if @endif

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

how to add opposite conditional to blade?

A

@unless @endunless

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

how to migrate in PHP artisan?

A

php artisan migrate

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

how to rollback in php artisan?

A

php artisan migrate:rollback

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

how to restart all migrations in php artisan?

A

php artisan migrate:refresh

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

what is the active record design pattern?

A

it’s an approach that connects the business application logic to a database table , allowing developers to work with the database using an object oriented paradigm

17
Q

what is the active record?

A

it’s an object that wraps a row in the database table, encapsulates the database access and provides an interface to query , insert , update and delete data from the database table.

18
Q

what is the encryption function for laravel?

19
Q

what are the properties in a model we use for mass assignment ( Model::create())

A

1 - fillable: allowed properties
2 - guarded : everything else is allowed but these

20
Q

what is a route model binding?

A

it is binding a route key to an eloquent model

21
Q

what are the specifications for route model binding?

A

1 - wild card must match with the variable model name
2 - it defaults to finding by id
3 - if we want it to find something by a specific column we make the key model:column

22
Q

how to make a migration with a model?

A

php artisan make:model Model -m

23
Q

what is the difference between has and belongsTo?

A

if a table has the foreign key then we use belongsTo

24
Q

what is the package we use to debug in browser?

25
how to fix n+1 problem in queries?
using eager loading not lazy loading with the help of function 'with'
26
how to migrate and seed at the same time?
php artisan migrate:fresh --seed
27
how to order in an eloquent model?
using latest();
28
how to eager load an existing model?
using load()
29
how to eager load inside the model itself?
using $with property
30
how to skip an iteration in a collection?
using skip()
31
what javascript library do we use with laravel?
alpine
32
how to check for equality in a collection?
using is();
33
what is a named route?
it's a route that you assign a name to
34
how to assign a name to a route?
using ->name() on Route method
35
how to make a controller using artisan?
php artisan make:controller ModelName
36
what to do when you want to write a method in a model?
use scopreMethodName()
37
what is the if condition for the query builder?
'when'