vendredi 28 août 2015

How can I apply transaction block across model methods?

I am making Db changes within controller by putting this transaction block:

DB::transaction(function () use($request) {
   $user = new User();
   $user->first_name = $request->input('first_name');
   $user->last_name = $request->input('last_name');
   $user->save();

  if($request->session()->get('title')!=''){
       $result = $project->add($request->session()->get('title'),$request->session()->get('summary'),$request->session()->get('files'));
DB::commit();
});

add() is defined as:

public function add($title,$summary,$files){

        dd('In model: '.$title);
        $this->title = $title;
        $this->summary = $summary;
        $this->files = $files;
        if($this->save())
        {
            dd($this->id);
            return $this->id;
        }
        else
        {
            dd('Not Saved');
            return -1;
        }

    }

The issue is, it's not storing $project object related info where add is a model method.

Can't I apply Transaction like that?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Uh6Lqp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire