I've use Larvel 5.0 with Database transaction all the method in my previous web application it work as well and we are really love it because this application help me much more than our estimated
so we have create another webs application by using this newest version of this framework and used the same Database structure but finaly it would not work for me and another one to. I have as more peoples and post on some toturial website for asking any belp but not yet get any solution so I record this video for sure about this case.
Issue: My issue I've disabled (//commit()) method all data still can insert into Database.
It is really not work.
Github repository : https://github.com/hengsoheak/personalEcommerce/tree/master/shop
Stackoverflow URL:
http://stackoverflow.com/questions/40151509/does-laravel-5-3019-database-transaction-method-work
use App\Http\Controllers\Controller;
use App\Models\Admin\Cat;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Admin\Products\Products;
use App\Models\Admin\CategoryDescriptions;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Contracts\Auth\Guard;
use League\Flysystem\Exception;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Notification;
use DB;
class CategoriesController extends AdminController
{
protected $data = null;
public function __construct(Request $request)
{
parent::__construct();
$this->middleware('auth');
$this->request = $request;
}
final function Add(Request $request)
{
if ($request->isMethod('post')) {
DB::beginTransaction();
$cats = new Cat();
$cats->parent_id = $request->input('category_id');//Tested with static method Request::Input()
$cats->status = ($request->input('status')) ? $request->input('status') : 0;
if ($res['result'] = $cats->save()) {
$catD = new CategoryDescriptions();
$catD->category_id = $cats->id;
$catD->language_id = 1;
$catD->name = $request->input('en_name');
if ($res['result'] = $catD->save()) {
$catD2 = new CategoryDescriptions();
$catD2->category_id = $cats->id;
$catD2->language_id = 2;
$catD2->name = $request->input('kh_name');
$res['result'] = $catD2->save();
}
}
//DB::commit() /// commit() method was disabled/
return $res;
}
$cat = Cat::with(['CategoryDescriptions', 'children'])->where('status', 1)->get();
return view('admin.categories.add', ['cat' => $cat]);
}
}
This is a duplicate of https://github.com/laravel/framework/issues/15972
I couldn't replicate the problem and transactions work fine based on my tests and all the apps I have access to.
I'll quote what I wrote on the previous issue:
Closing this issue since I can't replicate any problem, please feel free to ping me if you ever managed to write a piece of code on a fresh laravel installation that I can use to replicate the issue.
Please put a simple code that I can use on a fresh laravel 5.3 installation and check the problem, this is the code I've used:
DB::beginTransaction();
\App\User::create(['name' => 'asd', 'password' => 'zxcx', 'email' => 'zxc']);
DB::commit();
And it's working fine, if you remove the commit() method nothing gets saved to the DB.
Is it work for eloquent? and in document it will work all DB Builder and Eloquent/
Could you show me with save method?
Using the DB facade's transaction methods also controls transactions for the query builder and Eloquent ORM.
This is the document description
I read that and do the following construction but why just show me only create method?
Should you check it?
It really not work?
Should I reinstall LR?
Should I downgrade?
https://www.youtube.com/watch?v=UDT5racHW1k
Can you confirm that you are using InnoDB as table engine in Mysql? The older MyISAM does not support transactions.
Ohhhhhhhh My god,
I have forgot to think about this case.. It is really awesome.
Thanks for your commend.
I have forgot that point now it work
Most helpful comment
Can you confirm that you are using InnoDB as table engine in Mysql? The older MyISAM does not support transactions.