Skip to content

Commit

Permalink
Add validation for config controller (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
baijunyao committed Jun 22, 2020
1 parent 506f0d2 commit 321e213
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
10 changes: 2 additions & 8 deletions app/Http/Controllers/Admin/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Config\Update;
use App\Models\Config;
use Artisan;
use Illuminate\Http\Request;

class ConfigController extends Controller
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public function licenses()
return view('admin.config.licenses');
}

public function update(Request $request)
public function update(Update $request)
{
$configs = $request->except('_token');

Expand All @@ -81,12 +81,6 @@ public function update(Request $request)
}
}

if (isset($configs['204']) && empty($configs['204'])) {
flash_error(__('At least one disk must be set up for uploading files'));

return redirect()->back();
}

if (isset($configs['165']) && empty($configs['164'])) {
$configs['164'] = [];
}
Expand Down
45 changes: 45 additions & 0 deletions app/Http/Requests/Config/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Config;

use Illuminate\Foundation\Http\FormRequest;

class Update extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
];
}

/**
* @param \Illuminate\Validation\Validator $validator
*
* @return void
*/
public function withValidator($validator)
{
$validator->after(function ($validator) {
if ($this->has(204) && !in_array('public', $this->input(204))) {
$validator->errors()->add('204', __('Local drive must be checked'));
}
});
}
}
2 changes: 1 addition & 1 deletion resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"Article Copyright Word": "Copyright Article",
"Article Counts": "Nombre articles",
"Article List": "Liste articles",
"At least one disk must be set up for uploading files": "Au moins un disque doit être configuré pour le téléchargement de fichiers",
"Audited": "Audité",
"Author": "Auteur",
"Backup": "Sauvegarde",
Expand Down Expand Up @@ -115,6 +114,7 @@
"Links": "Liens",
"List": "Liste",
"Local": "Local",
"Local drive must be checked": "Le lecteur local doit être vérifié",
"Log in time": "Heure de connexion",
"Login times": "Temps de connexion",
"Logo Style": "Style de logo",
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"Article Copyright Word": "Слово копирайта статьи",
"Article Counts": "Количество статей",
"Article List": "Список статей",
"At least one disk must be set up for uploading files": "Как минимум один диск должен быть настроен для загрузки файлов",
"Audited": "Проверенные",
"Author": "Автор",
"Backup": "Резервное сохранение",
Expand Down Expand Up @@ -115,6 +114,7 @@
"Links": "Ссылки",
"List": "Список",
"Local": "Local",
"Local drive must be checked": "Локальный диск должен быть проверен",
"Log in time": "Время входа",
"Login times": "Время нахождения",
"Logo Style": "Стиль лого",
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"Article Copyright Word": "文章保留版权提示",
"Article Counts": "文章总数",
"Article List": "文章列表",
"At least one disk must be set up for uploading files": "至少要设置一个用于上传文件的磁盘",
"Audited": "已审核",
"Author": "作者",
"Backup": "备份",
Expand Down Expand Up @@ -115,6 +114,7 @@
"Links": "友情链接",
"List": "列表",
"Local": "本地",
"Local drive must be checked": "必须选中本地",
"Log in time": "登录时间",
"Login times": "登录次数",
"Logo Style": "Logo 风格",
Expand Down

0 comments on commit 321e213

Please sign in to comment.