Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1852 from Obi-Wana/master
(Feature) Add Internals System for Staff
- Loading branch information
Showing
13 changed files
with
589 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<?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 HDVinnie <hdinnovations@protonmail.com> | ||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 | ||
*/ | ||
|
||
namespace App\Http\Controllers\Staff; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Internal; | ||
use Carbon\Carbon; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* @see \Tests\Feature\Http\Controllers\Staff\GroupControllerTest | ||
*/ | ||
class InternalController extends Controller | ||
{ | ||
/** | ||
* Display All Internal Groups. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$user = $request->user(); | ||
\abort_unless($user->group->is_modo, 403); | ||
|
||
$internals = Internal::all()->sortBy('name'); | ||
|
||
return \view('Staff.internals.index', ['internals' => $internals]); | ||
} | ||
|
||
/** | ||
* Edit A group. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\Models\UsersVIP $id | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function edit(Request $request, $id) | ||
{ | ||
$user = $request->user(); | ||
\abort_unless($user->group->is_modo, 403); | ||
|
||
$date = Carbon::now(); | ||
$internal = Internal::findOrFail($id); | ||
|
||
return \view('Staff.internals.edit', ['internal' => $internal]); | ||
} | ||
|
||
/** | ||
* Save a group change. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\Models\UsersVIP $id | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function update(Request $request, $id) | ||
{ | ||
$user = $request->user(); | ||
\abort_unless($user->group->is_modo, 403); | ||
|
||
$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 \redirect()->route('staff.internals.index') | ||
->withErrors($v->errors()); | ||
} | ||
$internal->save(); | ||
|
||
return \redirect()->route('staff.internals.index') | ||
->withSuccess('Internal Group Was Updated Successfully!'); | ||
} | ||
|
||
/** | ||
* Internal Add Form. | ||
* | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
*/ | ||
public function create() | ||
{ | ||
return \view('Staff.internals.create'); | ||
} | ||
|
||
/** | ||
* Store A New Internal Group. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$user = $request->user(); | ||
\abort_unless($user->group->is_admin, 403); | ||
|
||
$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 \redirect()->route('staff.internals.index') | ||
->withErrors($v->errors()); | ||
} | ||
$internal->save(); | ||
|
||
return \redirect()->route('staff.internals.index') | ||
->withSuccess('New Internal Group added!'); | ||
} | ||
|
||
/** | ||
* Delete A Internal Group. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param $commentId | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function destroy(Request $request, $id) | ||
{ | ||
$user = $request->user(); | ||
$internal = Internal::findOrFail($id); | ||
|
||
\abort_unless($user->group->is_admin, 403); | ||
$internal->delete(); | ||
|
||
return \redirect()->route('staff.internals.index') | ||
->withSuccess('Group Has Been Removed.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?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 HDVinnie <hdinnovations@protonmail.com> | ||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 | ||
*/ | ||
|
||
namespace App\Models; | ||
|
||
use App\Traits\Auditable; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* App\Models\Group. | ||
* | ||
* @property int $id | ||
* @property string $name | ||
* @property string $icon | ||
* @property string $effect | ||
* | ||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Internal newModelQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Internal newQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Inernal query() | ||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Internal whereIcon($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Internal whereEffect($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Internal whereId($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Internal whereName($value) | ||
* @mixin \Eloquent | ||
*/ | ||
class Internal extends Model | ||
{ | ||
use HasFactory; | ||
use Auditable; | ||
|
||
/** | ||
* The Attributes That Aren't Mass Assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $guarded = ['id']; | ||
|
||
/** | ||
* Indicates If The Model Should Be Timestamped. | ||
* | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
|
||
/** | ||
* Has Many Users. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | ||
*/ | ||
public function users() | ||
{ | ||
return $this->hasMany(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
database/migrations/2021_04_18_085155_add_internals_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddInternalsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
//Create Table | ||
Schema::create('internals', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('name')->unique(); | ||
$table->string('icon')->default('none'); | ||
$table->string('effect')->default('none'); | ||
}); | ||
|
||
//Update Users Table | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->integer('internal_id')->index('fk_users_internal_idx')->after('group_id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
//Delete Table | ||
Schema::dropIfExists('internals'); | ||
|
||
//Update Users Table | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn('internal_id'); | ||
}); | ||
} | ||
} |
Oops, something went wrong.