Skip to content

Commit 28854cf

Browse files
committedOct 29, 2024
Refactor job listing and add Laravel Debugbar
Removed unused debugging in the home route and adjusted job fetching logic to include employer relationships. Enhanced job listing view for better styling and details display, including employer name. Configured the Laravel Debugbar for development and added model factory fields for first and last names.
1 parent 7af9917 commit 28854cf

File tree

7 files changed

+189
-16
lines changed

7 files changed

+189
-16
lines changed
 

‎app/Models/Job.php

+18
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,29 @@
22

33
namespace App\Models;
44

5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
56
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
68

79
class Job extends Model
810
{
11+
use HasFactory;
12+
913
// This is a special case where you can define the table name
1014
protected $table = 'job_listings';
15+
protected $fillable = [
16+
'title',
17+
'salary',
18+
];
19+
20+
public function employer(): BelongsTo
21+
{
22+
return $this->belongsTo(Employer::class);
23+
}
24+
25+
public function tags()
26+
{
27+
return $this->belongsToMany(Tag::class, foreignPivotKey: "job_listing_id");
28+
}
1129

1230
}

‎app/Providers/AppServiceProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\ServiceProvider;
67

78
class AppServiceProvider extends ServiceProvider
@@ -19,6 +20,7 @@ public function register(): void
1920
*/
2021
public function boot(): void
2122
{
22-
//
23+
// Disable lazy loading
24+
Model::preventLazyLoading();
2325
}
2426
}

‎composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"laravel/tinker": "^2.9"
1111
},
1212
"require-dev": {
13+
"barryvdh/laravel-debugbar": "^3.14",
1314
"fakerphp/faker": "^1.23",
1415
"laravel/pail": "^1.1",
1516
"laravel/pint": "^1.13",

‎composer.lock

+153-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎database/factories/UserFactory.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class UserFactory extends Factory
2424
public function definition(): array
2525
{
2626
return [
27-
'name' => fake()->name(),
27+
'first_name' => fake()->firstName(),
28+
'last_name' => fake()->lastName(),
2829
'email' => fake()->unique()->safeEmail(),
2930
'email_verified_at' => now(),
3031
'password' => static::$password ??= Hash::make('password'),

‎resources/views/jobs.blade.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<x-layout>
2-
<x-slot:heading>About Page</x-slot:heading>
3-
<h1>Hello from the Jobs Page.</h1>
4-
<ul>
2+
<x-slot:heading>Jobs Listing</x-slot:heading>
3+
<div class="space-y-4">
54
@foreach($jobs as $job)
6-
<li>
7-
<a href="/jobs/{{ $job['id'] }}" class="text-blue-500 hover:underline">
8-
<strong>{{ $job['title'] }}: Pays {{$job['salary']}} per year. </strong>
5+
<a href="/jobs/{{ $job['id'] }}" class="block px-4 py-6 border border-grey-200 rounded-lg">
6+
<div class="font-bold text-blue-500 text-sm">{{ $job->employer->name }}</div>
7+
<div>
8+
<strong>{{ $job['title'] }}: Pays {{$job['salary']}} per year. </strong>
9+
</div>
910
</a>
10-
</li>
1111
@endforeach
12-
</ul>
12+
</div>
1313
</x-layout>

‎routes/web.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
use Illuminate\Support\Facades\Route;
55

66
Route::get('/', static function () {
7-
$Jobs = Job::all();
8-
9-
dd($Jobs);
10-
// return view('home');
7+
return view('home');
118
});
129

1310
Route::get('/jobs', static function () {
11+
$JobsWithEmployer = Job::with('employer')->get();
12+
1413
return view('jobs', [
15-
'jobs' => Job::all(),
14+
'jobs' => $JobsWithEmployer,
1615
]);
1716
});
1817

0 commit comments

Comments
 (0)
Please sign in to comment.