0% found this document useful (0 votes)
20 views4 pages

Store Data in Database in Laravel Using Query Builder Et ORM Eloquent

it a lesson about laravel

Uploaded by

khaoula00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Store Data in Database in Laravel Using Query Builder Et ORM Eloquent

it a lesson about laravel

Uploaded by

khaoula00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Store Data in database in Laravel using Query

Builder et ORM Eloquent :

Mèthode 1 : Model ( $model->property )


NB. On doit avoir le modéle Product

Méthode 2 : Model Create


NB. On doit declarer fillable liste au niveau du modèle Product

Méthode 3 : Model Create with $request->all() method

Note: If you save as shown below, make sure to add all the fields in your $fillable
property in your Model ( Eg. Product.php Model )
Example for fillable property in your model:
Méthode 4 : Model Create with $request->only() method

Méthode 5 : New Model

Méthode 6 : Model using Fill() method and save()

Méthode 7 : using Query Builder


Méthode 8 : Save data using insert() with Model:

Méthode 9 : Model with firstOrCreate() method to save data.

Méthode 10 : Model with firstOrNew() method to save data.


The firstOrNew() method in Laravel's Eloquent ORM is used to retrieve the first record
matching the specified attributes. If no matching record is found, it will only be saved to the
database when you explicitly do so (calling save() on the model). Otherwise, it will give you
the matched item. Here's an example of how firstOrNew() can be used in Laravel:

Métode 11 : Model with updateOrCreate() method to save


data.
The updateOrCreate() method in Laravel's Eloquent ORM is used to find a record that
matches the given attributes. If found, it updates the record with the specified values; if not
found, it creates a new record with the provided attributes. Here's an example demonstrating
the usage of updateOrCreate():

You might also like