private function loadBudgetsData($budgetId, $masterBriefingId, $activeTab) { $isAdding = true; if (!isset($activeTab)) { $activeTab = "#list"; } $masterBriefingId = isset($masterBriefingId) ? $masterBriefingId : -1; $masterBriefing = null; $versionNumber = 1; $lastVersionDate = null; $nextBudgetId = 1; $budgets = null; //DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = '$someVariable'")); // Incorrect way //DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = :somevariable"), array('somevariable' => $someVariable,)); // Safe way $lastBudgetId = DB::select(DB::raw("SELECT AUTO_INCREMENT AS nextId FROM information_schema.TABLES WHERE (TABLE_NAME = 'budgets')")); if (isset($lastBudgetId)) { $nextBudgetId = $lastBudgetId[0]->nextId; } if ($masterBriefingId > 0) { $budgets = Budget::where('briefing_id', $masterBriefingId)->orderBy('date_budget', 'DESC')->orderBy('created_at', 'DESC')->get(); $masterBriefing = Briefing::find($masterBriefingId); } else { $budgets = Budget::orderBy('date_budget', 'DESC')->orderBy('created_at', 'DESC')->get(); } $budgetTypes = BudgetType::orderBy('id', 'ASC')->get(); $addEditTitleLabel = trans('budgets.add'); $relationships = array('budgetTypes' => $budgetTypes); if (isset($budgetId)) { $isAdding = false; $addEditTitleLabel = trans('budgets.edit'); $budgetToEdit = Budget::find($budgetId); if (!$budgetToEdit) { return Redirect::to(route('get_budgets')); } else { $versionNumber = $budgetToEdit->budgetVersionCount(); $lastVersionDate = $budgetToEdit->budgetVersions->last()->date_budget_version; return View::make('pages.budgets.index')->with('isAdding', $isAdding)->with('activeTab', $activeTab)->with('addEditTitleLabel', $addEditTitleLabel)->with('budgets', $budgets)->with('relationships', $relationships)->with('budgetToEdit', $budgetToEdit)->with('masterBriefingId', $masterBriefingId)->with('masterBriefing', $masterBriefing)->with('nextBudgetId', $nextBudgetId)->with('versionNumber', $versionNumber)->with('lastVersionDate', $lastVersionDate); } } else { return View::make('pages.budgets.index')->with('isAdding', $isAdding)->with('activeTab', $activeTab)->with('addEditTitleLabel', $addEditTitleLabel)->with('budgets', $budgets)->with('relationships', $relationships)->with('masterBriefingId', $masterBriefingId)->with('masterBriefing', $masterBriefing)->with('nextBudgetId', $nextBudgetId)->with('versionNumber', $versionNumber)->with('lastVersionDate', $lastVersionDate); } }
public function removeBudget(Request $request) { $id = $request->input('id'); $budget = Budget::where('id', $id)->first(); if (isset($budget)) { $budget->status = 'removed'; $budget->save(); return json_encode(array('message' => 'removed')); } else { return json_encode(array('message' => 'notfound', 'id' => $id)); } }