How can we create a record in Laravel using eloquent

0 votes
How can i create the record in laravel?
Mar 20, 2020 in Laravel by kartik
• 37,510 points
939 views

1 answer to this question.

0 votes

We need to create a new model instance if we want to create a new record in the database using Laravel eloquent. Then we are required to set attributes on the model and call the save() method.

Example:

                    public functionsaveProduct(Request $request )  

                     $product = new product;  

                     $product->name = $request->name;  

                     $product->description = $request->name;  

                      $product->save();  
answered Mar 20, 2020 by Niroj
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

How to update a pivot table using Eloquent in laravel 5?

Hello @kartik, The code below solved my problem: $messages ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,880 points
4,024 views
0 votes
1 answer

How can I create a unique random string in laravel?

Hello @kartik, You can use : sha1(time()) Explanation: sha1 is ...READ MORE

answered Sep 25, 2020 in Laravel by Niroj
• 82,880 points
3,240 views
0 votes
1 answer

How to alias a table in Laravel Eloquent queries using Query Builder?

Hello @kartik, You can use less code, writing ...READ MORE

answered Nov 11, 2020 in Laravel by Niroj
• 82,880 points
9,935 views
0 votes
1 answer

How can I create a migration to add a value to an enum in eloquent?

Hello @kartik, Try using this code: public function up() ...READ MORE

answered Nov 12, 2020 in Laravel by Niroj
• 82,880 points
2,255 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,354 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,077 views
0 votes
1 answer

Display Laravel in browser by using cmd promt?

Hello, First you need to have laravel install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
933 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
728 views
0 votes
1 answer

How can we Create Multiple Where Clause Query Using Laravel Eloquent?

Hii, You can use Conditions using Array: $users = User::where([ ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,880 points
16,161 views
0 votes
1 answer

How to manually create a new empty Eloquent Collection in Laravel?

Hello @kartik, It's not really Eloquent, to add ...READ MORE

answered Aug 11, 2020 in Laravel by Niroj
• 82,880 points
12,156 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP