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

Commit

Permalink
#88 Add channels management
Browse files Browse the repository at this point in the history
  • Loading branch information
Studio384 committed Dec 1, 2020
1 parent 522676a commit 7ad6ddd
Show file tree
Hide file tree
Showing 12 changed files with 508 additions and 80 deletions.
45 changes: 45 additions & 0 deletions app/Channel.php
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
);
}
}
106 changes: 106 additions & 0 deletions app/Http/Controllers/Admin/ChannelController.php
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.');
}
}
8 changes: 6 additions & 2 deletions app/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ class Platform extends Model implements Searchable {
protected $fillable = ['name', 'color', 'icon', 'active', 'slug'];
protected $appends = ['plain_icon', 'colored_icon'];

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

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

public function getBgColorAttribute() {
return 'background-color: #'.$this->color;
}

public function getRouteKeyName() {
return 'slug';
}
Expand Down
Loading

0 comments on commit 7ad6ddd

Please sign in to comment.