COM431_serverside_development/routes/web.php

64 lines
948 B
PHP

<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('home', ['greeting'=>'Hello']);
});
Route::get('/jobs', function () {
return view('jobs', [
'jobs'=> Job::all()
]);
});
class Job {
public static function all():array
{
return [[
'id'=>1,
'title'=>'Manager',
'salary'=>'$50,000'
],
[
'id'=>2,
'title'=>'Engineer',
'salary'=>'$40,000'
],
[
'id'=>3,
'title'=>'Assisstant',
'salary'=>'$30,000'
]
];
}
}
// return view('jobs', ['jobs' => $jobs]);
// });
Route::get('/contact', function() {
return view('contact');
});
Route::get('/jobs/{id}', function($id) {
$jobs=[
[
'id'=>1,
'title'=>'Manager',
'salary'=>'$50,000'
],
[
'id'=>2,
'title'=>'Engineer',
'salary'=>'$40,000'
],
[
'id'=>3,
'title'=>'Assisstant',
'salary'=>'$30,000'
]
];
$job=\Illuminate\Support\Arr::first($jobs, function ($job) use ($id) {
return $job['id']==$id;
});
return view('job',['job'=>$job]);
});