How to creat and Update Laravel Eloquent

0 votes

This is my code:

<?php

$shopOwner = ShopMeta::where('shopId', '=', $theID)
    ->where('metadataKey', '=', 2001)->first();

if ($shopOwner == null) {
    // Insert new record into database
} else {
    // Update the existing record
}

What's the shorthand for inserting a new record or updating if it exists?

Oct 19, 2020 in PHP by kartik
• 37,520 points
722 views

1 answer to this question.

0 votes

Hello @kartik,

Here's a full example of what "lu cip" was talking about:

$user = User::firstOrNew(array('name' => Input::get('name')));
$user->foo = Input::get('foo');
$user->save();

Hope it works!!

answered Oct 19, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How to set a default attribute value for a Laravel / Eloquent model?

Hello @kartik, This is what I'm doing now: protected ...READ MORE

answered Nov 8, 2020 in PHP by Niroj
• 82,840 points
5,076 views
0 votes
1 answer

How to route GET and POST for same pattern in Laravel?

Hello @kartik, You could try the following: Route::controller('login','AuthController'); Then in ...READ MORE

answered Nov 22, 2020 in PHP by Niroj
• 82,840 points
3,103 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
10,540 views
0 votes
1 answer

How to validate E-mail and URL of Php form?

hey, The code below shows a simple way ...READ MORE

answered Feb 13, 2020 in PHP by manish
2,363 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,995 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,705 views
0 votes
1 answer

How to get the Last Inserted Id Using Laravel Eloquent?

Hello @kartik, Firstly create an object, Then set ...READ MORE

answered Jul 22, 2020 in PHP by Niroj
• 82,840 points
17,442 views
0 votes
1 answer

How to include External CSS and JS file in Laravel?

Hello @kartik, The right way is this one: <script ...READ MORE

answered Oct 27, 2020 in PHP by Niroj
• 82,840 points
28,643 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