Home > php > Laravel create method returning null

Laravel create method returning null

November 10Hits:4

I have this problem. I have a Group and Role models, with a Many-to-Many relationship setup.

Group model

public function roles() {     return $this->belongsToMany('App\Role', 'group_roles'); } 

Role Model

public function groups() {     return $this->belongsToMany('App\Group', 'group_roles'); } 

GroupsController store method

public function store(Request $requests) {     $group = new Group;     //$group->group_name = $requests->group_name;     //$group->save();     $group->create($requests->all());      $group->roles()->sync($requests->input('roles'));      Session::flash('success', $requests->group_name.' successfully added');    return redirect('/settings/groups/groups'); 


The problem I have here is that when I call create method on the group model, it returns null, thus causing this $group->roles()->sync($requests->input('roles')); to fail. However, when I use the save method, it works flawlessly. Why doesn't the create work?

Related Articles

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 2.391 s.