app\models\Closet::remove PHP Method

remove() public method

Remove a texture from closet.
public remove ( integer $tid ) : boolean
$tid integer
return boolean
    public function remove($tid)
    {
        $offset = 0;
        // traverse items
        foreach ($this->textures as $item) {
            if ($item['tid'] == $tid) {
                $this->items_modified[] = $tid;
                // remove element from array
                return array_splice($this->textures, $offset, 1);
            }
            $offset++;
        }
        return false;
    }

Usage Example

コード例 #1
0
 public function remove(Request $request)
 {
     $this->validate($request, ['tid' => 'required|integer']);
     if ($this->closet->remove($request->tid)) {
         $t = Texture::find($request->tid);
         $t->likes = $t->likes - 1;
         $t->save();
         return json(trans('user.closet.remove.success'), 0);
     } else {
         return json(trans('user.closet.remove.non-existent'), 0);
     }
 }