File tree 7 files changed +189
-16
lines changed
7 files changed +189
-16
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Models ;
4
4
5
+ use Illuminate \Database \Eloquent \Factories \HasFactory ;
5
6
use Illuminate \Database \Eloquent \Model ;
7
+ use Illuminate \Database \Eloquent \Relations \BelongsTo ;
6
8
7
9
class Job extends Model
8
10
{
11
+ use HasFactory;
12
+
9
13
// This is a special case where you can define the table name
10
14
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
+ }
11
29
12
30
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Providers ;
4
4
5
+ use Illuminate \Database \Eloquent \Model ;
5
6
use Illuminate \Support \ServiceProvider ;
6
7
7
8
class AppServiceProvider extends ServiceProvider
@@ -19,6 +20,7 @@ public function register(): void
19
20
*/
20
21
public function boot (): void
21
22
{
22
- //
23
+ // Disable lazy loading
24
+ Model::preventLazyLoading ();
23
25
}
24
26
}
Original file line number Diff line number Diff line change 10
10
"laravel/tinker" : " ^2.9"
11
11
},
12
12
"require-dev" : {
13
+ "barryvdh/laravel-debugbar" : " ^3.14" ,
13
14
"fakerphp/faker" : " ^1.23" ,
14
15
"laravel/pail" : " ^1.1" ,
15
16
"laravel/pint" : " ^1.13" ,
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ class UserFactory extends Factory
24
24
public function definition (): array
25
25
{
26
26
return [
27
- 'name ' => fake ()->name (),
27
+ 'first_name ' => fake ()->firstName (),
28
+ 'last_name ' => fake ()->lastName (),
28
29
'email ' => fake ()->unique ()->safeEmail (),
29
30
'email_verified_at ' => now (),
30
31
'password ' => static ::$ password ??= Hash::make ('password ' ),
Original file line number Diff line number Diff line change 1
1
<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" >
5
4
@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 >
9
10
</a >
10
- </li >
11
11
@endforeach
12
- </ul >
12
+ </div >
13
13
</x-layout >
Original file line number Diff line number Diff line change 4
4
use Illuminate \Support \Facades \Route ;
5
5
6
6
Route::get ('/ ' , static function () {
7
- $ Jobs = Job::all ();
8
-
9
- dd ($ Jobs );
10
- // return view('home');
7
+ return view ('home ' );
11
8
});
12
9
13
10
Route::get ('/jobs ' , static function () {
11
+ $ JobsWithEmployer = Job::with ('employer ' )->get ();
12
+
14
13
return view ('jobs ' , [
15
- 'jobs ' => Job:: all () ,
14
+ 'jobs ' => $ JobsWithEmployer ,
16
15
]);
17
16
});
18
17
You can’t perform that action at this time.
0 commit comments