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

Installing PHP 7 on digitalocean
Laravel Redirect and Undefined Variabale
Replacing href value of all <a> elemnts without link with .mp3 extention
How to fix Fatal Error after consecutive calls to MySQLi_Connect?
Mysqli SELECT COUNT (*) FROM table returning false
Tooltip with MySQL query
pagination not working for taxonomy
PHP -> simplexml_load_file skip to next when error
How to correct and change a static method to a non-static method for Joomla module
How to individual print every word of a sentence in PHP? [closed]
JetBrains PhpStorm Not Resolving Server Variable?
couldn't fetch session value to another page
Edit YAML array with php Symfony2.8
preg_replace and hidden chars or hidden encoding
BelongsToMany with BelongsToMany relation [closed]
What is equivalent of strtotime in SQL?

Categories

HOME
knockout.js
facebook-messenger
kendo-dropdown
writefile
ontology
azure-data-lake
onvif
angular2-template
yeoman-generator-angular
cqrs
getopenfilename
orc
jquery-select2-4
cuba-platform
trace32
squid
mahout-recommender
fresco
checkout
pfobject
bluemix-mobile-services
jitsi
kamailio
quartz.net
high-availability
echosign
annotation-processing
cube
laravel-4.2
social-networking
dotcms
steam-web-api
argv
private-key
serversocket
testlink
ftp-server
strapi
mars-simulator
recovery
sspi
pyttsx
1wire
nomad
zend-form
vesta
react-intl
absolute
qvtkwidget
tinyioc
sony-future-lab-n
photoswipe
android-webservice
glassfish-4.1
dymola
adobe-reader
email-injection
nitrousio
haraka
researchkit
ipywidgets
okio
msg
gnucash
apple-configurator
m4
opencyc
roxygen2
whitespace-language
r.java-file
html-escape-characters
jcheckbox
hp-idol-ondemand
utf8-decode
visual-studio-6
xcode6.3.1
typesafe-stack
armv6
django-settings
application-server
mute
django-facebook
tnt4j
sunstudio
delphi-xe4
django-filebrowser
contextswitchdeadlock
nsmutablestring
stretch
first-class
java.lang.class
representation
directshow.net
grails-validation
gaelyk
jdownloader
resharper-5.0
mysqli-multi-query
bucket
downcasting
index.dat
iphone-sdk-3.1.3
activex-exe
rootkit

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