Enhance careers management features: update CareersPageController to fetch and display career listings with additional fields, modify Career model to include relationships and new attributes, and create a new view for the careers index with an application modal. Update database migration to reflect changes in the careers table structure and adjust routes for application submissions.
This commit is contained in:
1 parent
9b3ca3ff66
commit
a89e2a71d8
15 files changed
+535
-11
No files matched your search
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\CareerResource\Pages;
|
||||
use App\Filament\Resources\CareerResource\RelationManagers;
|
||||
use App\Models\Career;
|
||||
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;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
|
||||
class CareerResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Career::class;
|
||||
|
||||
protected static ?string $navigationGroup = 'Careers';
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-briefcase';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('location')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
Textarea::make('title_description')
|
||||
->label('Description (show on modal)')
|
||||
->required()
|
||||
->maxLength(65535)
|
||||
->columnSpan('full'),
|
||||
|
||||
TextInput::make('salary_per_month')
|
||||
->required()
|
||||
->numeric()
|
||||
->label('Salary per month')
|
||||
->maxLength(255),
|
||||
Repeater::make('bullets')
|
||||
->schema([
|
||||
TextInput::make('bullet')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
])
|
||||
->minItems(1)
|
||||
->defaultItems(1)
|
||||
->columnSpan('full'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('title_description')
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('salary_per_month')
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('location')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('salary')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\ApplicationsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCareers::route('/'),
|
||||
'create' => Pages\CreateCareer::route('/create'),
|
||||
'edit' => Pages\EditCareer::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CareerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\CareerResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCareer extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CareerResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CareerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\CareerResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCareer extends EditRecord
|
||||
{
|
||||
protected static string $resource = CareerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CareerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\CareerResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCareers extends ListRecords
|
||||
{
|
||||
protected static string $resource = CareerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CareerResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class ApplicationsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'applications';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\DatePicker::make('birthdate')
|
||||
->required(),
|
||||
Forms\Components\FileUpload::make('resume_file')
|
||||
->required()
|
||||
->acceptedFileTypes(['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'])
|
||||
->disk('public') // or your preferred disk
|
||||
->directory('resumes'),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->email()
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('phone_number')
|
||||
->required()
|
||||
->maxLength(20),
|
||||
Forms\Components\Textarea::make('cover_letter')
|
||||
->maxLength(65535)
|
||||
->nullable()
|
||||
->columnSpan('full'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('email')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('phone_number')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Application;
|
||||
|
||||
class ApplicationController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'career_id' => 'required|exists:careers,id',
|
||||
'name' => 'required|string|max:255',
|
||||
'birthdate' => 'required|date',
|
||||
'resume_file' => 'required|file|mimes:pdf,doc,docx|max:2048',
|
||||
'email' => 'required|email|max:255',
|
||||
'phone_number' => 'required|string|max:20',
|
||||
'cover_letter' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$resumePath = $request->file('resume_file')->store('resumes');
|
||||
|
||||
Application::create([
|
||||
'career_id' => $validatedData['career_id'],
|
||||
'name' => $validatedData['name'],
|
||||
'birthdate' => $validatedData['birthdate'],
|
||||
'resume_file' => $resumePath,
|
||||
'email' => $validatedData['email'],
|
||||
'phone_number' => $validatedData['phone_number'],
|
||||
'cover_letter' => $validatedData['cover_letter'] ?? null,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Your application has been submitted successfully!');
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,9 @@ class CareersPageController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('web.pages.careers.index');
|
||||
}
|
||||
$careers = Career::query()->get();
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
dd($request->all());
|
||||
return view('web.pages.careers.index', compact('careers'));
|
||||
}
|
||||
|
||||
public function show(Career $career)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use App\Models\Career;
|
||||
|
||||
class Application extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'career_id',
|
||||
'name',
|
||||
'birthdate',
|
||||
'resume_file',
|
||||
'email',
|
||||
'phone_number',
|
||||
'cover_letter',
|
||||
];
|
||||
|
||||
public function career(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Career::class);
|
||||
}
|
||||
}
|
||||
+14
-2
@@ -3,13 +3,25 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use App\Models\Application;
|
||||
|
||||
class Career extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'description',
|
||||
'title_description',
|
||||
'salary_per_month',
|
||||
'bullets',
|
||||
'location',
|
||||
'salary',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'bullets' => 'array',
|
||||
];
|
||||
|
||||
public function applications(): HasMany
|
||||
{
|
||||
return $this->hasMany(Application::class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user