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
how to inject a module within another module by zend framework 2?
How to gather form data in a single cell of the database?
Laravel “At Least One” Field Required Validation
Login with ajax not working
Wordpress Custom Post Type Form Redirects to Page Not Found
Laravel 4 cannot drop foreign key
MySQL better approach to check duplicate entry
Storing images on linux
Update HTML table every 5 seconds with mySQL, and PHP?
Bllim DataTables in Laravel 4 throws undefined getQuery() exception
Written html source code in downloaded file from php page
Making a simple search engine php mysql
Make a different IF depending on which page the user came from
PHP Output (function swap) [closed]
spl_autoload_register and properties of the $class variable
PHP Function “opendir()” in Wordpress. Works in one file, but not in other