This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#87 Add platform platform create and eidt
- Loading branch information
Showing
13 changed files
with
739 additions
and
4 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
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.'); | ||
} | ||
} |
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,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 | ||
); | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.