In this laravel eloquent model tutorial we will explain some data store methods like save(), create() and insert() now we read one by one
laravel store methods.
- save()
- create()
- insert()
save()
laravel provides a simple method to save data this method does not save more than one row by one query. Below example given store method which save our data.
public function store(Request $request){ $student = new Student; $student->name = 'anmol sharma'; $student->email = 'anmol@gmail.com'; $student->phone = '1234567890'; $student->save(); }
create()
laravel create() method store data by model and it also store mass data so before we use create method fillable or guarded model configuration required let an example of create method.
public function store(Request $request){ $data = [ 'name' => 'anmol sharma', 'email' = 'anmol@gmail.com', 'phone' = '1234567890' ]; $create = Student::create($data); }
insert()
llaravel insert() also insert mass data and it inserts many rows by run query once so for creating many rows in table we use laravel model insert() method.
public function store(Request $request){ $data = [ [ 'name' => 'anmol sharma', 'email' = 'anmol@gmail.com', 'phone' = '1234567890' ], [ 'name' => 'advanced web', 'email' = 'web@gmail.com', 'phone' = '3456543457' ] ]; $insert = Student::insert($data); }
Anmol Sharma
I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.
Related tutorial links
- What is laravel eloquent model and introduction
- part 1 laravel eloquent model all configuration hindi
- part 2 laravel insert and create data by eloquent model tutorial
- part 3 laravel data retrieve method
- part 4 first, find, findOrFail and firstOrFail method
- part 5 laravel delete vs truncate method
- part 6 laravel save vs update method
- part 7 laravel updateOrCreate and upsert
- part 8 laravel chunk vs cursor method
- part 9 laravel eloquent subquery select
- part 10 laravel findOrFail vs firstOrFail
- part 11 laravel create and retrieve data
- part 12 laravel eloquent aggregate functions
- part 13 laravel isDirty vs isClean vs wasChanged method