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.
- Loading branch information
Showing
12 changed files
with
508 additions
and
80 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,45 @@ | ||
<?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 Channel extends Model implements Searchable { | ||
use Sluggable; | ||
use HasFactory; | ||
|
||
public $searchableType = 'Channels'; | ||
|
||
protected $table = 'channels'; | ||
protected $fillable = ['name', 'color', 'position', 'slug']; | ||
|
||
public function getBgColorAttribute() { | ||
return 'background-color: '.$this->color; | ||
} | ||
|
||
public function getRouteKeyName() { | ||
return 'slug'; | ||
} | ||
|
||
public function sluggable() { | ||
return [ | ||
'slug' => [ | ||
'source' => 'name' | ||
] | ||
]; | ||
} | ||
|
||
public function getSearchResult(): SearchResult { | ||
$url = route('admin.channels.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Channel; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Str; | ||
|
||
class ChannelController extends Controller { | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() { | ||
$this->authorize('show_channels'); | ||
|
||
$channels = Channel::all(); | ||
|
||
return view('core.channels.index', compact('channels')); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) { | ||
$this->authorize('create_channel'); | ||
|
||
$this->validate(request(), [ | ||
'name' => ['required'], | ||
'color' => ['required'], | ||
'position' => ['required'] | ||
], [ | ||
'name.required' => 'The name is required.', | ||
'color.required' => 'The color is required.', | ||
'position.required' => 'The position is required.' | ||
]); | ||
|
||
$channel = Channel::create([ | ||
'name' => request('name'), | ||
'color' => '#'.request('color'), | ||
'position' => request('position') | ||
]); | ||
|
||
return redirect()->route('admin.channels.edit', $channel)->with('status', 'The channel <b>'.$channel->name.'</b> has been added.'); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param \App\Channel $channel | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit(Channel $channel) { | ||
$this->authorize('edit_channel'); | ||
|
||
return view('core.channels.edit', compact('channel')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\Channel $channel | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, Channel $channel) { | ||
$this->authorize('edit_channel'); | ||
|
||
$this->validate(request(), [ | ||
'name' => ['required'], | ||
'color' => ['required'], | ||
'position' => ['required'] | ||
], [ | ||
'name.required' => 'The name is required.', | ||
'color.required' => 'The color is required.', | ||
'position.required' => 'The position is required.' | ||
]); | ||
|
||
$channel->update([ | ||
'name' => request('name'), | ||
'color' => '#'.request('color'), | ||
'position' => request('position') | ||
]); | ||
|
||
return redirect()->route('admin.channels')->with('status', 'The changes to <b>'.$channel->name.'</b> have been saved.'); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\Channel $channel | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(Channel $channel) { | ||
$this->authorize('delete_channel'); | ||
|
||
$channel->delete(); | ||
|
||
return redirect()->route('admin.channels')->with('status', 'The channel <b>'.$channel->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
Oops, something went wrong.