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?

A

bcrypt();

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?

A

clockwork

25
Q

how to fix n+1 problem in queries?

A

using eager loading not lazy loading with the help of function ‘with’

26
Q

how to migrate and seed at the same time?

A

php artisan migrate:fresh –seed

27
Q

how to order in an eloquent model?

A

using latest();

28
Q

how to eager load an existing model?

A

using load()

29
Q

how to eager load inside the model itself?

A

using $with property

30
Q

how to skip an iteration in a collection?

A

using skip()

31
Q

what javascript library do we use with laravel?

A

alpine

32
Q

how to check for equality in a collection?

A

using is();

33
Q

what is a named route?

A

it’s a route that you assign a name to

34
Q

how to assign a name to a route?

A

using ->name() on Route method

35
Q

how to make a controller using artisan?

A

php artisan make:controller ModelName

36
Q

what to do when you want to write a method in a model?

A

use scopreMethodName()

37
Q

what is the if condition for the query builder?

A

‘when’