-
app/Policies/JobApplicationPolicy.php
Open in GitHubuse App\Models\User; use App\Models\JobApplication; class JobApplicationPolicy { use HandlesAuthorization; public function before(User $user) { if ($user->isAdmin()) { return true; } } public function view(User $user, JobApplication $jobApplication) { return $jobApplication->job->user_id === $user->id; } public function updateStatus(User $user, JobApplication $jobApplication) { return $jobApplication->job->user_id === $user->id; } }
-
app/Models/User.php
Open in GitHubuse Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { // ... public function isAdmin() { return $this->user_type === 'admin'; } // .. }
-
app/Http/Controllers/Admin/JobApplicationController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Models\JobApplication; use Illuminate\Support\Facades\Storage; use Inertia\Inertia; class JobApplicationController extends Controller { public function view(JobApplication $jobApplication) { $this->authorize('view', $jobApplication); $jobApplication->load('job', 'job.location', 'job.department', 'job.contractType'); return Inertia::render('Dashboard/JobApplication', compact('jobApplication')); } public function updateStatus(JobApplication $jobApplication) { $this->authorize('updateStatus', $jobApplication); $oldStatus = $jobApplication->status; $jobApplication->update([ 'status' => request('status'), ]); session()->flash('success', __('Job application status updated successfully from :oldStatus to :newStatus', [ 'oldStatus' => $oldStatus, 'newStatus' => $jobApplication->status, ])); return back(); } public function downloadPDF(JobApplication $jobApplication) { $this->authorize('view', $jobApplication); $cvPDF = $jobApplication->resume; return response()->download(Storage::path($cvPDF)); } }