mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-02-11 14:09:31 -06:00
refactor: move internal requests to form requests
This commit is contained in:
@@ -14,8 +14,9 @@
|
||||
namespace App\Http\Controllers\Staff;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Staff\StoreInternalRequest;
|
||||
use App\Http\Requests\Staff\UpdateInternalRequest;
|
||||
use App\Models\Internal;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* @see \Tests\Feature\Http\Controllers\Staff\GroupControllerTest
|
||||
@@ -45,26 +46,9 @@ class InternalController extends Controller
|
||||
/**
|
||||
* Save a group change.
|
||||
*/
|
||||
public function update(Request $request, int $id): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateInternalRequest $request, int $id): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$internal = Internal::findOrFail($id);
|
||||
|
||||
$internal->name = $request->input('name');
|
||||
$internal->icon = $request->input('icon');
|
||||
$internal->effect = $request->input('effect');
|
||||
|
||||
$v = \validator($internal->toArray(), [
|
||||
'name' => 'required',
|
||||
'icon' => 'required',
|
||||
'effect' => 'required',
|
||||
]);
|
||||
|
||||
if ($v->fails()) {
|
||||
return \to_route('staff.internals.index')
|
||||
->withErrors($v->errors());
|
||||
}
|
||||
|
||||
$internal->save();
|
||||
Internal::where('id', '=', $id)->update($request->validated());
|
||||
|
||||
return \to_route('staff.internals.index')
|
||||
->withSuccess('Internal Group Was Updated Successfully!');
|
||||
@@ -81,25 +65,9 @@ class InternalController extends Controller
|
||||
/**
|
||||
* Store A New Internal Group.
|
||||
*/
|
||||
public function store(Request $request): \Illuminate\Http\RedirectResponse
|
||||
public function store(StoreInternalRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$internal = new Internal();
|
||||
$internal->name = $request->input('name');
|
||||
$internal->icon = $request->input('icon');
|
||||
$internal->effect = $request->input('effect');
|
||||
|
||||
$v = \validator($internal->toArray(), [
|
||||
'name' => 'required|unique:internals',
|
||||
'icon',
|
||||
'effect',
|
||||
]);
|
||||
|
||||
if ($v->fails()) {
|
||||
return \to_route('staff.internals.index')
|
||||
->withErrors($v->errors());
|
||||
}
|
||||
|
||||
$internal->save();
|
||||
Internal::create($request->validated());
|
||||
|
||||
return \to_route('staff.internals.index')
|
||||
->withSuccess('New Internal Group added!');
|
||||
|
||||
39
app/Http/Requests/Staff/StoreInternalRequest.php
Normal file
39
app/Http/Requests/Staff/StoreInternalRequest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author Roardom <roardom@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\Staff;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreInternalRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'icon' => 'required',
|
||||
'effect' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
39
app/Http/Requests/Staff/UpdateInternalRequest.php
Normal file
39
app/Http/Requests/Staff/UpdateInternalRequest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author Roardom <roardom@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\Staff;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateInternalRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'icon' => 'required',
|
||||
'effect' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@ class Internal extends Model
|
||||
use Auditable;
|
||||
|
||||
/**
|
||||
* The Attributes That Aren't Mass Assignable.
|
||||
*
|
||||
* @var array
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Indicates If The Model Should Be Timestamped.
|
||||
|
||||
Reference in New Issue
Block a user