Skip to content

Commit

Permalink
Merge pull request #26 from eng-gabrielscardoso/24-enhancement-abilit…
Browse files Browse the repository at this point in the history
…y-to-interact-with-skills-in-admin-panel

[ENHANCEMENT] Ability to interact with skills in admin panel
  • Loading branch information
eng-gabrielscardoso authored Jul 13, 2024
2 parents c094fe9 + cdbe41e commit 8d36a16
Show file tree
Hide file tree
Showing 19 changed files with 587 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ FILAMENT_FILESYSTEM_DISK="${FILESYSTEM_DISK}"

TRUST_HOSTS="laravel.test"
TRUST_PROXIES=""

SKILLS_ICON_API_URL="https://go-skill-icons.vercel.app/api/icons?i="
SKILLS_ICON_REPOSITORY_URL="https://github.com/LelouchFR/skill-icons"
104 changes: 104 additions & 0 deletions app/Filament/Resources/SkillResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\SkillResource\Pages;
use App\Filament\Resources\SkillResource\RelationManagers;
use App\Models\Skill;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class SkillResource extends Resource
{
protected static ?string $model = Skill::class;

protected static ?string $navigationIcon = 'heroicon-o-sparkles';

public static function form(Form $form): Form
{
$repositoryLink = config('app.skills_icon_repository_url');

return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('description')
->required()
->maxLength(255),
Forms\Components\TextInput::make('skills')
->required()
->maxLength(255)
->helperText("Please include the skills separated by comma e.g. `rabbitmq,kafka`. To see the complete list of available icon skills, please visit: {$repositoryLink}"),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('description')
->searchable(),
Tables\Columns\TextColumn::make('skills')
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListSkills::route('/'),
'create' => Pages\CreateSkill::route('/create'),
'view' => Pages\ViewSkill::route('/{record}'),
'edit' => Pages\EditSkill::route('/{record}/edit'),
];
}

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}
12 changes: 12 additions & 0 deletions app/Filament/Resources/SkillResource/Pages/CreateSkill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Filament\Resources\SkillResource\Pages;

use App\Filament\Resources\SkillResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateSkill extends CreateRecord
{
protected static string $resource = SkillResource::class;
}
22 changes: 22 additions & 0 deletions app/Filament/Resources/SkillResource/Pages/EditSkill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Filament\Resources\SkillResource\Pages;

use App\Filament\Resources\SkillResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditSkill extends EditRecord
{
protected static string $resource = SkillResource::class;

protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/SkillResource/Pages/ListSkills.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\SkillResource\Pages;

use App\Filament\Resources\SkillResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListSkills extends ListRecords
{
protected static string $resource = SkillResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/SkillResource/Pages/ViewSkill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\SkillResource\Pages;

use App\Filament\Resources\SkillResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewSkill extends ViewRecord
{
protected static string $resource = SkillResource::class;

protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}
66 changes: 66 additions & 0 deletions app/Http/Controllers/SkillController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreSkillRequest;
use App\Http\Requests\UpdateSkillRequest;
use App\Models\Skill;

class SkillController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreSkillRequest $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(Skill $skill)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Skill $skill)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateSkillRequest $request, Skill $skill)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Skill $skill)
{
//
}
}
28 changes: 28 additions & 0 deletions app/Http/Requests/StoreSkillRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreSkillRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}
28 changes: 28 additions & 0 deletions app/Http/Requests/UpdateSkillRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateSkillRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}
11 changes: 11 additions & 0 deletions app/Livewire/Home/Skills.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

namespace App\Livewire\Home;

use App\Models\Skill;
use Livewire\Component;

class Skills extends Component
{
/**
* @var \Illuminate\Database\Eloquent\Collection<Skill>|null
*/
public $skills = null;

public function render()
{
return view('components.home.skills');
}

public function mount()
{
$this->skills = Skill::orderBy('created_at')->get();
}
}
40 changes: 40 additions & 0 deletions app/Models/Skill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Skill extends Model
{
use HasFactory, SoftDeletes;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'description',
'skills',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [];
}
}
Loading

0 comments on commit 8d36a16

Please sign in to comment.