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

Cannot add image to a Zabbix GUI
Plesk, enable multiple PHP instances of same versions
Passing Values from One Form to another redirected Form in PHP
Session variable and Dynamic Pagination in php
Page not reloading upon hitting submit button
How do you allow index.php in .htaccess rewrite rule
How to install Laravel app in subfolder
Redirect to URL from artisan command
how to handle timezone in my app when user publishes something
if statement is not working not giving a output
Notice: Undefined offset preg_split [duplicate]
Get checkbox value in Excel Spreadsheet with PHP
header location is not working after processing the process_student.php page
PHP - need to output array values in order and if one does not exist print blank space
Unable to find template Symfony 3
Podio widget update order

Categories

HOME
elasticsearch
openshift
svn
yahoo-weather-api
windows-10
code-formatting
hdfs
websocket
malware
mosquitto
stored-procedures
onvif
anchor
polymer-2.x
elastic-load-balancer
game-maker
xbap
amazon-elb
jaspersoft-studio
multiple-tables
android-permissions
multi-upload
channel
ava
eclipse-emf
quartz.net
window-managers
points
django-import-export
basic-authentication
xenapp
steam-web-api
series
adminer
cmis
numerics
django-smart-selects
imgur
angular-datatables
swift2.3
roracle
supertest
scala-breeze
beeline
comm
openstack-glance
entropy
watir-webdriver
msxml
degrees
google-shopping-api
gawk
boost-compute
cocoa-bindings
java-2d
thread-exceptions
system.web.optimization
wininet
callouts
traversable
qtcpsocket
ajaxmin
gnucash
codecharge
adjacency-list
fdt
gdl
deeplink
largenumber
http.client
gitlab-omnibus
hmisc
libz
roxygen2
fuseesb
directorysearcher
device-admin
adwords-apiv201402
relationships
two.js
prism.js
reference-counting
nodeload
meteorite
code39
ggts
acitree
apportable
spiral
semicolon
dojo-1.9
xalan
border-box
thejit
jzmq
prefuse
kobold2d
wiktionary
expression-web
tablet-pc
regression-testing
sqlsitemapprovider
icon-language
twitter-feed
gui-designer

Resources

Encrypt Message