Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
#87 Add platform platform create and eidt
Browse files Browse the repository at this point in the history
  • Loading branch information
Studio384 committed Nov 30, 2020
1 parent 850fdc8 commit 522676a
Show file tree
Hide file tree
Showing 13 changed files with 739 additions and 4 deletions.
107 changes: 107 additions & 0 deletions app/Http/Controllers/Admin/PlatformController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Platform;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class PlatformController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$this->authorize('show_platforms');

$platforms = Platform::all();

return view('core.platforms.index', compact('platforms'));
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
$this->authorize('create_platform');

$this->validate(request(), [
'name' => ['required'],
'color' => ['required'],
'icon' => ['required']
], [
'name.required' => 'The name is required.',
'color.required' => 'The color is required.',
'icon.required' => 'The icon is required.'
]);

$platform = Platform::create([
'name' => request('name'),
'color' => '#'.request('color'),
'icon' => request('icon')
]);

return redirect()->route('admin.platforms.edit', $platform)->with('status', 'The platform <b>'.$platform->name.'</b> has been added.');
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Platform $platform
* @return \Illuminate\Http\Response
*/
public function edit(Platform $platform) {
$this->authorize('edit_platform');

return view('core.platforms.edit', compact('platform'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Platform $platform
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Platform $platform) {
$this->authorize('edit_platform');

$this->validate(request(), [
'name' => ['required'],
'color' => ['required'],
'icon' => ['required']
], [
'name.required' => 'The name is required.',
'color.required' => 'The color is required.',
'icon.required' => 'The icon is required.'
]);

$platform->update([
'name' => request('name'),
'color' => '#'.request('color'),
'icon' => request('icon'),
'active' => request('active') !== null ? 1 : 0
]);

return redirect()->route('admin.platforms')->with('status', 'The changes to <b>'.$platform->name.'</b> have been saved.');
}

/**
* Remove the specified resource from storage.
*
* @param \App\Platform $platform
* @return \Illuminate\Http\Response
*/
public function destroy(Platform $platform) {
$this->authorize('delete_platform');

$platform->delete();

return redirect()->route('admin.platforms')->with('status', 'The platform <b>'.$platform->name.'</b> has been removed.');
}
}
50 changes: 50 additions & 0 deletions app/Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Spatie\Searchable\Searchable;
use Spatie\Searchable\SearchResult;

class Platform extends Model implements Searchable {
use Sluggable;
use HasFactory;

public $searchableType = 'Platforms';

protected $table = 'platforms';
protected $fillable = ['name', 'color', 'icon', 'active', 'slug'];
protected $appends = ['plain_icon', 'colored_icon'];

function getPlainIconAttribute() {
return '<i class="far fa-fw fa-'.$this->icon.' '.$this->icon_modifiers.'"></i>';
}

function getColoredIconAttribute() {
return '<i style="color: '.$this->color.'" class="far fa-fw fa-'.$this->icon.' '.$this->icon_modifiers.'"></i>';
}

public function getRouteKeyName() {
return 'slug';
}

public function sluggable() {
return [
'slug' => [
'source' => 'name'
]
];
}

public function getSearchResult(): SearchResult {
$url = route('admin.platforms.edit', $this);

return new SearchResult(
$this,
$this->name,
$url
);
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"php": "^7.2.0",
"barryvdh/laravel-cors": "^2.0",
"blade-ui-kit/blade-ui-kit": "^0.2",
"cviebrock/eloquent-sluggable": "^8.0",
"erusev/parsedown": "^1.7",
"facade/ignition": "^2.3.6",
"fideloper/proxy": "^4.0",
Expand All @@ -16,9 +17,9 @@
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0",
"spatie/laravel-feed": "^3.0",
"spatie/laravel-searchable": "^1.7",
"thujohn/twitter": "^2.2",
"tymon/jwt-auth": "^1.0",
"spatie/laravel-searchable": "^1.7"
"tymon/jwt-auth": "^1.0"
},
"require-dev": {
"filp/whoops": "^2.0",
Expand Down
135 changes: 134 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 522676a

Please sign in to comment.