Skip to content

Commit c035ab6

Browse files
committed
0149-job-policy
1 parent bd8c46b commit c035ab6

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

job-board/app/Http/Controllers/JobApplicationController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ class JobApplicationController extends Controller
99
{
1010
public function create(Job $job)
1111
{
12+
$this->authorize('apply', $job);
1213
return view('job_application.create', ['job' => $job]);
1314
}
1415

1516
public function store(Job $job, Request $request)
1617
{
18+
$this->authorize('apply', $job);
1719
$job->jobApplications()->create([
1820
'user_id' => $request->user()->id,
1921
...$request->validate([
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace App\Policies;
4+
5+
use App\Models\Job;
6+
use App\Models\User;
7+
use Illuminate\Auth\Access\Response;
8+
9+
class JobPolicy
10+
{
11+
/**
12+
* Determine whether the user can view any models.
13+
*/
14+
public function viewAny(?User $user): bool
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* Determine whether the user can view the model.
21+
*/
22+
public function view(?User $user, Job $job): bool
23+
{
24+
return true;
25+
}
26+
27+
/**
28+
* Determine whether the user can create models.
29+
*/
30+
public function create(User $user): bool
31+
{
32+
return false;
33+
}
34+
35+
/**
36+
* Determine whether the user can update the model.
37+
*/
38+
public function update(User $user, Job $job): bool
39+
{
40+
return false;
41+
}
42+
43+
/**
44+
* Determine whether the user can delete the model.
45+
*/
46+
public function delete(User $user, Job $job): bool
47+
{
48+
return false;
49+
}
50+
51+
/**
52+
* Determine whether the user can restore the model.
53+
*/
54+
public function restore(User $user, Job $job): bool
55+
{
56+
return false;
57+
}
58+
59+
/**
60+
* Determine whether the user can permanently delete the model.
61+
*/
62+
public function forceDelete(User $user, Job $job): bool
63+
{
64+
return false;
65+
}
66+
67+
public function apply(User $user, Job $job): bool
68+
{
69+
return false;
70+
}
71+
}

job-board/resources/views/job/show.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<p class="mb-4 text-sm text-slate-500">
66
{!! nl2br(e($job->description)) !!}
77
</p>
8+
9+
<x-link-button :href="route('job.application.create', $job)">
10+
Apply
11+
</x-link-button>
812
</x-job-card>
913

1014
<x-card class="mb-4">

0 commit comments

Comments
 (0)