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

Regex to match alphanumeric characters, underscore, periods and dash, allowing dot and dash only in the middle
Setting Facebook PHP SDK access_token with setAccessToken()
How do I modify the path used by exec in php
Broken link check while initiating cron-multi
How to format `23/05/2012` into insertable value in DATETIME column?
will users see post on their wall,if a post is made on app page
Wordpress Loop passing variables
PHP Imagick - setTextEncoding() function doesn't work
Upload PHP Code not uploading image
Why create own request object? [closed]
array declration methods in php [closed]
File extension filter when choosing file to upload
Secure file storage in a server
MySQL: Avoid selecting columns with the same userid
Can't view local images with apache
Bug in Doctrine or am I doing something wrong?

Categories

HOME
orientdb
apple-push-notifications
plaid
gentelella
video-streaming
supercollider
telegraf
bellman-ford
azure-graph-api
lc3
parsley.js
circleci
live-streaming
pushdown-automaton
django-rq
mahout-recommender
orange-api
pywinauto
libgit2
coreldraw
mime-types
websphere-portal
chronicle-queue
bonita
javax.persistence
audit
d3.js-v4
reporting
universal
android-collapsingtoolbar
java-stream
formsauthenticationticket
redgate
variable-variables
hidden-markov-models
uipickerview
resampling
dagger
music21
return-type
android-5.0-lollipop
beeline
sigsegv
punctuation
android-mediarecorder
stateless-session-bean
nclam
data-management
ftp-client
msbuild-4.0
android-4.2-jelly-bean
android-sdcard
eclemma
jemdoc
gulp-uglify
taco
seadragon
grinder
deeplink
ibm-was
cfwheels
jnlp
hmisc
compositetype
darwin
console.log
scala-swing
dnsjava
datagridcomboboxcolumn
image-rotation
xml-signature
jini
particle-swarm
disjoint-union
semicolon
dojo-1.9
simplecov
jquery-dialog
struts2-json-plugin
android-dialog
instance-variables
sfinae
websphere-6.1
system-information
dropshadow
uploading
rtd
mongrel2
downgrade
ios-4.2
principles
cleartype
self-tracking-entities
facebook-fbml
yahoo-maps
source-code-protection
jboss-mdb

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