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

XML content inside PHP variable
Store array and update record in database using codeignitor
Active page always showing as strong/bold, Code Igniter Pagination
Codeigniter array to object conversation
Why is Propel is always setting created_at and updated at to the same value?
Use the first match count of matches in select statement
Sending mail using phpmailer is showing success but not getting delivered [duplicate]
Warning: Invalid argument supplied for foreach() -> MySQL Connecting [duplicate]
Codeigniter dynamic url for pages breaks routes
How to test Doctrine Migrations?
When to hardcode data inside the source code, when to use the database, and when to use a web service?
Closing connection in order to get remaining queries to run [closed]
Multiple recipients email php
Wildcard subdomain redirecting to a file
Laravel where if statemnet
PHP file can't connect to my database?

Categories

HOME
cocoapods
yaml
ontouchlistener
clearcase
add-on
mousemove
dafny
out-of-memory
twitter-fabric
yql
mirc
greasemonkey
iptables
apache-kafka-connect
gprs
wagtail
scheduler
reportviewer
swarm
solution
cqrs
alljoyn
stimulsoft
squirrel-sql
cocos2d-android
tfsbuild
renderscript
scheduled-tasks
activeadmin
tableview
vuforia
react-dnd
background-color
android-service
network-analysis
history.js
sendmessage
caesar-cipher
directfb
buildforge
des
jade4j
aurelia-cli
ms-dos
ng-repeat
iscroll
assemblies
python-sounddevice
plane
yoast
httphandler
git-tfs
reverse-dns
vesta
react-intl
wysihtml5
sonicmq
punctuation
watir-webdriver
htmlspecialchars
case-when
gmaps.js
pecl
cognos-tm1
petsc
cocoa-bindings
ipywidgets
groovyfx
wicked-pdf
sharepoint-apps
taco
management-studio-express
vim-plugin
dsa
blank-line
ngcordova
html-escape-characters
dnsjava
wicket-1.5
xml-signature
quantify
oracle-adf-mobile
xcode6.3.1
lumia-imaging-sdk
coding-efficiency
screwturn
fileshare
pre
facebook-game-groups
ember-table
jacob
jbox2d
android-authenticator
oembed
examine
cgrectmake
instance-variables
workflow-manager-1.x
popup-blocker
cakeyframeanimation
struts2-s2hibernate
pcspim
nosetests
photo-management
pyjamas
ccl
getimagesize
firephp
fuzzy-comparison
gtktextview
server-load

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile