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

jQuery - On click, check all checkboxes in class, if checked (do this) if not (then)
XML in to a PHP does not display an array
Storing details in cookie
Enable server cache for a specific folder
Next/Previous Page bug
Blade returns undefined offset
PayPal button: How to return a specified value when a payment is successful?
codeigniter unable to send email
PHP - CURL Connection to a Website that uses Office365 to login
php checkdate, check each argument individually
Why am i getting error: recv() failed (104: Connection reset by peer) while reading response header from upstream during ajax request
Inserting an item after specific array pattern
session var lost while switching pages & session_save_path saving an empty file
Get error severity in Laravel 5
mysql statement to get the rank of a given row id in an ordered result set
PDO Exception Error

Categories

HOME
nam
yii
couchdb
softlayer
swi-prolog
windows-10
subdomain
ant
initialization
openlayers-3
docker-cloud
autocomplete
qooxdoo
swift2
dji-sdk
bittorrent
repair
hspi
scrape
amazon-emr
phpstorm-2017.1
business-intelligence
xbap
freertos
mailgun
django-rq
max-msp-jitter
synthesis
user-defined-types
maven-plugin
office-ui-fabric
tfsbuild
clr
coreldraw
strophe.js
onchange
ibm-connections
dnsmasq
es6-modules
aurelia-http-client
hidden-markov-models
task-parallel-library
utf
game-center
dredd
comm
winmerge
mongodb-aggregation
stateless-session-bean
lvalue
polymaps
oid
allegro
yui3
openquery
seccomp
perforce-integrate
bbc-micro
univocity
teensy
html.actionlink
largenumber
lowercase
android-studio-import
auto-generate
extend
sqlbase
relational-model
dbmigrate
python-c-extension
incron
fiware-bosun
global-scope
zend-mail
visual-studio-6
igor
lmax
ecos
aho-corasick
git-reset
xulrunner
smips
xsd2code
insertonsubmit
stty
ax
node.js-stream
jacob
acceptance-testing
microformats
blobstorage
eager-loading
html-frames
itunes-sdk
stretch
getopt-long
kobold2d
type-safety
affinetransform
will-paginate
jquery-1.4
grails-validation
android-2.1-eclair
icicles
yahoo-maps
source-code-protection
prism-2
objectinstantiation
acceleration

Resources

Encrypt Message