Home laravel 7.2 Laravel 7.2 Best Practices Database Queries

Laravel 7.2 Best Practices Database Queries

by therichpost
5 comments
Laravel 7.2 routing with route group auth guard check with prefix

Hello to all, welcome to therichpost.com. In this post, I will tell, Laravel 7.2 Best Practices Database Queries.

Here are the some basics laravel database queries easy to understand. Laravel is the best php mvc framework.

1. Laravel Eloquent Insert Query :

// I am doing this in controller file

//Employees -->Modal Name
$employees = new Employees;
$employees->name = $request->name;
$employees->email = $request->email;
$employees->phone = $request->phone;
$employees->gender = $request->gender;
$employees->save();

 

2. Laravel Eloquent Select Query  and output will be json format:

//I am using this in controller file

//Employees -->Modal Name

Employees::all();

 

3. Laravel Eloquent Delete Query :

//I am doing this in controller file

//Employees -->Modal name
Employees::where('id',$request->id)->delete();

 

4. Laravel Eloquent Update Query :

//I am doing this in controller


//Employees -->Modal name

$employees = Employees::find($request->id);
$employees->name = $request->name;
$employees->email = $request->email;
$employees->phone = $request->phone;
$employees->gender = $request->gender;
$employees->save();

 

If you have any kind of query then please do comment below.

Jassa

Thank you

You may also like

5 comments

Jackwander March 31, 2020 - 3:35 am

You can do this also in insert.
Employees::create([$request]);
Only if the payloads of form you’ve submitted and the table column name are identical.

Reply
Ajay Malhotra March 31, 2020 - 5:22 am

Correct!!

Reply
Bernard April 3, 2020 - 10:09 pm

Can u write an article to show how u can perform CRUD with types of laravel relation .

Reply
Ajay Malhotra April 4, 2020 - 5:11 am

Yes sure @bernard.

Reply
Bernard April 3, 2020 - 10:11 pm

I mean laravel relationship

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.