Eloquent Flashcards

1
Q

First thing before CRUD eloquent in laravel?

A

declare protected $fillable=[ …] in Model

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

Before CRUD eloquent in Laravel,what do you have to do?

A

declare protected $fillable=[..] in Model.php file!!

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

Create Method

A
Example:::
Post::create([
              'title'=>'post two',
              'description'=>'post two desc'
          ]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Read all or Select all

A

$posts= Post::all();
foreach ($posts as $post){
echo $post->title;
}

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

Select one

A

$post = Post::find(1);

echo $post;

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

Update Method

A

$post = Post::find(1)->update([
‘title’=>’post one one’,
‘description’=>’post oneeee desc’
]);

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

Delete Method

A

Post::destroy(3);

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

Get by limit number

A

$posts= Post::take(number)->get();
foreach ($posts as $post){
echo $post->title;
}

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

Get latest data

A

$posts= Post::latest->get();
foreach ($posts as $post){
echo $post->title;
}

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

inserting image

A

$image->$request->file(‘image’)
$name_gen=hexdec(uniqid( ));
$img_ext = strtolower($brand_image->GetClientOriginalExtension( ) );
$img_name = $name_gen . ‘ . ‘ . $img_ext;
$up_location =’/image/’;
$last_img = $up_location.$img_name;
$image->move($up_location,$img_name)

save last_image

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