Beispiel #1
0
 public function getSubscribers()
 {
     return Subscription::subscribers($this);
 }
Beispiel #2
0
function error($msg)
{
    http_response_code(500);
    die(json_encode(['error' => $msg]));
}
try {
    switch ($request) {
        case 'stock':
            $stock = new Stock();
            $stock->company = Request::any('company');
            $stock->price = Request::any('price');
            if (!$stock->company || !$stock->price) {
                error('Invalid Input');
            }
            $stock->save();
            $subscribers = Subscription::subscribers($stock);
            foreach ($subscribers as $sub) {
                $msg = "Stock Update\n{$stock->company}: {$stock->price}";
                $sub->send($msg);
            }
            echo json_encode($stock);
            break;
        case 'stocks':
            $stocks = Stock::findAll();
            echo json_encode($stocks);
            break;
        case 'delete':
            $company = Request::any('company');
            $stock = Stock::find($company);
            $stock->delete();
            echo json_encode($stock);