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

PHP Error: T_CONSTANT_ENCAPSED_STRING [duplicate]
.htaccess Remove trailing / unless directory
Don't allow new user, if a user has already logged in
Error Fetching http headers in wsdltophp.com
function results in Notice: Undefined offset: 0 on one website but not the other
send mail in laravel 5.4 with request input
Php generated wrong format url file path after upload to server
Php PDO search string as Google or order by best match
Submitting the same value many times when the value needs to be unique
'Order by' specified order in Woocommerce shortcode
woocommerce hooks warning “function not found”
How to acces value from route in symfony2
Get Value Of Table Field
redirecting a long URL to https
How to embed this php code in html?
Uncaught Error: Call to undefined function curl_init()

Categories

HOME
google-chrome
paypal-ipn
enums
swi-prolog
activex
stacktrace.js
code-formatting
nsview
dronekit-python
greasemonkey
mosquitto
share
haxe
mithril.js
pyresttest
tweepy
yahoo
siesta
fasm
orc
spring-jpa
temperature
hidden
varnish-vcl
function-points
password-generator
gravity-forms-plugin
annotation-processing
macromedia
amazon-cloudtrail
javax.persistence
fatfs
amazon-iam
guice
locks
dotcms
progid
netbios
fotorama
seafile-server
autoencoder
keyboard-layout
subclassing
hidden-markov-models
plane
distributed-caching
raytracing
word-cloud
fiware-wirecloud
jqgrid-asp.net
git-tfs
gcal
realstudio
deployd
icecast
uiautomatorviewer
password-hash
head.js
comm
word-2007
stateless-session-bean
1010
emacs25
fitbit
nrf51
pjax
xcode6.4
wininet
declarative
piping
static-methods
powerpoint-2013
enunciate
lovefield
opencyc
auto-generate
gql
org-babel
erlog
azure-xplat-cli
xml-signature
aho-corasick
rpg
senchatouch-2.4
meteor-collections
preorder
profiles
typesafe-stack
ggts
mute
ax
objective-c-runtime
flv
web-frameworks
oembed
examine
onconfigurationchanged
playorm
quartz-core
background-repeat
infopath-2007
libxslt
ccnet-config
main-method
rendering-engine

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App