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

CakePHP3 “Helper not found” error in plugin
Laravel Eloquent extract data into custom array
Parsing HTTP POST in PHP using REGEX?
Strange file_get_contents behavior
Show loop content according to value, inside another loop
PHP glob(): At least one of the passed flags is invalid or not supported on this platform in
set session array and get the values in other pages without using database in php
get specific colunm from latest five record in the MySQL DB
Validation error message doesn't appear in View?
How to install phpChart lite library?
How to use PHP to return an image to Objective-C?
Exiting a php cron job with continue
SQL Injection with an Escaped String?
Symfony projects messing up the cache
password_verify doesn't verify hash
What would be the proper sql query to use, in order to echo from my two tables?

Categories

HOME
ionic2
events
artificial-intelligence
user-interface
firebase
protocol-buffers
concurrency
apk
informatica
autocomplete
dronekit-python
mosquitto
firebase-dynamic-links
sympy
feature-extraction
rest-assured
android-5.1.1-lollipop
tomcat8
opam
device
quartz.net
pdf.js
tracing
sap-lumira
mdns
splunk-query
jsonresult
d3.js-v4
mongodb-3.4
sca
flipkart
apache-toree
destroy
linq-to-excel
gcal
image-registration
nonlinear-functions
sonicmq
entropy
webvtt
mura
palindrome
glimpse
maatwebsite-excel
bilinear-interpolation
carmen
tsqlt
oci
jeasyui
jeditable
persistent-object-store
flush
voronoi
gdl
apache-commons-digester
directx-9
nastran
dsa
enaml
espresso
unhandled
web-api
mathematical-expressions
nhibernate-criteria
symja
iodocs
full-text-indexing
incognito-mode
rails-api
bittorrent-sync
oxygene
windows-taskbar
ctp
hyphen
revmob
ax
node.js-stream
jacob
contextswitchdeadlock
red-system
ckeditor.net
stretch
server-name
image-scanner
prefuse
hardcode
multidrop-bus
litespeed
qtextbrowser
motodev-studio
haiku
vows
bll
dip
channelfactory
raw-data
html-components
eai
autobench

Resources

Encrypt Message