app\models\Closet::add PHP Method

add() public method

Add an item to the closet.
public add ( integer $tid, string $name ) : boolean
$tid integer
$name string
return boolean
    public function add($tid, $name)
    {
        foreach ($this->textures as $item) {
            if ($item['tid'] == $tid) {
                return false;
            }
        }
        $this->textures[] = array('tid' => $tid, 'name' => $name, 'add_at' => time());
        $this->items_modified[] = $tid;
        return true;
    }

Usage Example

 public function add(Request $request)
 {
     $this->validate($request, ['tid' => 'required|integer', 'name' => 'required|no_special_chars']);
     if ($this->closet->add($request->tid, $request->name)) {
         $t = Texture::find($request->tid);
         $t->likes += 1;
         $t->save();
         return json(trans('user.closet.add.success', ['name' => $request->input('name')]), 0);
     } else {
         return json(trans('user.closet.add.repeated'), 1);
     }
 }