tethys/app/Http/Controllers/Settings/LicenseController.php

68 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2018-08-06 12:30:51 +00:00
<?php
namespace App\Http\Controllers\Settings;
use App\Http\Controllers\Controller;
2018-09-10 13:09:10 +00:00
use App\Models\License;
use App\Models\Language;
2018-08-06 12:30:51 +00:00
use App\Http\Requests\LicenseRequest;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\DB;
2018-09-12 15:30:42 +00:00
use App\Exceptions\GeneralException;
2018-08-06 12:30:51 +00:00
class LicenseController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index() : View
{
2018-10-10 16:28:51 +00:00
$direction = 'asc'; // or desc
$licenses = License::orderBy('sort_order', $direction)->get();
2018-08-06 12:30:51 +00:00
return view('settings.license.license', compact('licenses'));
}
public function edit($id): View
{
$license = License::findOrFail($id);
//$languages = Language::where('active', true)->pluck('part2_t');
$languages = DB::table('languages')
->where('active', true)
->pluck('part1', 'part1');
2018-08-06 12:30:51 +00:00
return view('settings.license.edit', compact('license', 'languages'));
}
2018-08-29 15:18:15 +00:00
public function update(Request $request, $id): RedirectResponse
2018-08-06 12:30:51 +00:00
{
2018-08-29 15:18:15 +00:00
$validatedData = $this->validate($request, [
'desc_text' => 'max:4000',
'language' => 'max:3',
'link_licence' => 'required|url:max:255',
'link_logo' => 'url|max:255',
'mime_type' => 'max:30',
'name_long' => 'required|min:5|max:255',
'sort_order' => 'required|integer',
'active' => 'required|boolean',
'pod_allowed' => 'required|boolean',
]);
2018-08-06 12:30:51 +00:00
$license = License::findOrFail($id);
$input = $request->all();
2018-09-12 15:30:42 +00:00
if ($license->update($input)) {
// event(new PageUpdated($page));
return redirect()
->route('settings.license')
->with('flash_message', 'You have updated the license!');
}
throw new GeneralException(trans('exceptions.backend.licenses.update_error'));
// $license->update($input);
// session()->flash('flash_message', 'You have updated the license!');
// return redirect()->route('settings.license');
2018-08-06 12:30:51 +00:00
}
}