firefly-iii/app/Http/Controllers/Budget/DeleteController.php

97 lines
2.7 KiB
PHP
Raw Normal View History

2018-07-14 08:22:21 -05:00
<?php
/**
* DeleteController.php
2020-01-31 00:32:04 -06:00
* Copyright (c) 2019 james@firefly-iii.org
2018-07-14 08:22:21 -05:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-07-14 08:22:21 -05:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-07-14 08:22:21 -05:00
*
* This program is distributed in the hope that it will be useful,
2018-07-14 08:22:21 -05:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-07-14 08:22:21 -05:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-07-14 08:22:21 -05:00
*/
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Budget;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Http\Request;
/**
*
* Class DeleteController
*/
class DeleteController extends Controller
{
2018-07-21 01:06:24 -05:00
/** @var BudgetRepositoryInterface The budget repository */
2018-07-14 08:22:21 -05:00
private $repository;
/**
2018-07-21 01:06:24 -05:00
* DeleteController constructor.
* @codeCoverageIgnore
2018-07-14 08:22:21 -05:00
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
2018-07-15 02:38:49 -05:00
app('view')->share('title', (string)trans('firefly.budgets'));
2018-07-14 08:22:21 -05:00
app('view')->share('mainTitleIcon', 'fa-tasks');
$this->repository = app(BudgetRepositoryInterface::class);
return $next($request);
}
);
}
/**
2018-07-21 01:06:24 -05:00
* Deletes a budget.
*
2018-07-14 08:22:21 -05:00
* @param Budget $budget
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function delete(Budget $budget)
{
2018-07-15 02:38:49 -05:00
$subTitle = (string)trans('firefly.delete_budget', ['name' => $budget->name]);
2018-07-14 08:22:21 -05:00
// put previous url in session
$this->rememberPreviousUri('budgets.delete.uri');
return view('budgets.delete', compact('budget', 'subTitle'));
}
/**
2018-07-21 01:06:24 -05:00
* Destroys a budget.
*
2018-07-14 08:22:21 -05:00
* @param Request $request
* @param Budget $budget
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroy(Request $request, Budget $budget)
{
$name = $budget->name;
$this->repository->destroy($budget);
$request->session()->flash('success', (string)trans('firefly.deleted_budget', ['name' => $name]));
app('preferences')->mark();
return redirect($this->getPreviousUri('budgets.delete.uri'));
}
}