php


Update Database Using Laravel Eloquent


I have a problem updating my database, it is working fine using the general DB:: method but I think it would be better to use Eloquent.
The general DB method I used (which worked):
\DB::table('subscriptions')->update(array('state' => 'active'));
The Eloquent method I used (and it doesn't work):
$user = $request->user();
$user-> subscription-> state = 'active';
$user-> save();
Thanks for helping me!
\DB::table('subscriptions')->update(array('state' => 'active'));
When you do that you're updating the state of every row. Assuming you have proper relationship setup, you do one of the below.
$subscription = $request->user()->subscription;
$subscription->state = 'active';
$subscription->save();
$request->user()->subscription()->update(array('state' => 'active'));

Related Links

yii, show records from different tables with same structure
count in model scopes() function
PHP Best Practice to Update one record and delete another record
Drupal 7 commerce module billing country selection based on user
Hiding Server Version Not Working [closed]
angularjs ng-click or ng-init? php variables
How can I “register” a static reference to an external variable from within a class [duplicate]
running php shell_exec WITHOUT returning results to browser?
Autofill textbox (php) [closed]
How to make PHP for loop with condition?
Incorrect timestamp in phpmyadmin db
Does first() return a collection in Laravel? Can i access the properties directly without using toArray()?
if ELSE statement not working correctly in while loop
How to add post thumbnail in a nested list ordered by year and month in wordpress
PHP's exec() printing output — doesn't seem to follow specs
PHP Mysql ranking

Categories

HOME
google-chrome
libgdx
mod-rewrite
mc
weblogic12c
workflow
devexpress
ews
hdfs
odata
fogbugz
tibco
implicit-conversion
clone
tup
jpa-criteria
fasm
nexus3
mailmerge
google-awareness
django-rq
corona
asp.net-core-1.0
async-await
pygobject
nose
azure-machine-learning
weex
sqlplus
pubxml
webviewclient
android-cardview
network-analysis
tsung
region
private-key
restful-architecture
pdfminer
formsauthenticationticket
cordys-opentext
telephonymanager
pyttsx
word-cloud
julius-speech
transparency
ol3-google-maps
exc-bad-access
pen
test-data
email-forwarding
gmaps.js
zend-server
http4s
adobe-reader
bpms
annotatorjs
allegro
cefpython
dojo-build
fiber
odp.net-managed
uibinder
simian
accessibilityservice
taco
currency-exchange-rates
textpattern
html.actionlink
fanotify
ora-04091
ambiguity
sequence-sql
subview
sql-processor
string.format
image-rotation
nesper
distributed-r
air-native-extension
lync-2010
django-sites
particle-swarm
autonumber
saga
illuminate-container
application-server
mousemotionlistener
coalesce
hints
html-frames
multiple-dispatch
taskkill
kolite
qtextbrowser
servlet-container
bll
android-2.1-eclair
iphone-sdk-3.1.3
remote-working

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile