如何使用Laravel在href中传递ID以在下一页显示详细信息

时间:2019-07-03 07:46:46

标签: laravel

实际上我正在获取所有头寸详细信息,但是我需要在单击数据表中头寸列表中的按钮时显示特定头寸的详细信息。

demo1.blade.php

@foreach ($jobposts as $jobpost)
<tr>
<td>{{ $jobpost->job_code }}</td>
<td>{{ $jobpost->position }}</td>
<td>{{ $jobpost->department }}</td>
    <td>{{ $jobpost->location }}</td>
<td>{{ $jobpost->employement_type }}</td>
<td>{{ $jobpost->created_at }}</td>
<td><a href="/demo2"><button class="btn btn-default btn- 
    apply">Apply</button></a></td>
</tr>
@endforeach

demo2.blade.php

@foreach ($jobposts as $jobpost)

<h4 class="heading color">Basic Eligibility Criteria: {{ $jobpost->position }}</h4>
<hr>

<p><strong>Job Code:</strong>  {{ $jobpost->job_code }}  </p>

<p><strong>Job Discription:</strong>  {{ $jobpost->job_discription }}   </p>

<p><strong>Skills Required:</strong>  {{ $jobpost->skills_required }}  </p>

<p><strong>Eligibility:</strong>  {{ $jobpost->eligibility }}  </p>

<p><strong>Package:</strong>  {{ $jobpost->package }}  </p>

<p><strong>Department:</strong>  {{ $jobpost->department }}  </p>

<p><strong>Location:</strong>  {{ $jobpost->location }}   </p>

<p><strong>Employement Type:</strong>  {{ $jobpost->employement_type }}  </p>

<p><strong>Note:</strong>  {{ $jobpost->detail }}  </p>

@endforeach

DemoController.php

public function index()
{
    $jobposts = DB::table('jobposts')->select('job_code','position','department','location','employement_type','created_at')->get();

    return view('home.demo1')->with('jobposts', $jobposts);
}

public function jobcode()
{
    $jobposts = DB::table('jobposts')->get();

    return view('home.demo2')->with('jobposts', $jobposts);
}

web.php

Route::get('/demo1', 'CareerController@index');
Route::get('/demo2', 'CareerController@jobcode');

1 个答案:

答案 0 :(得分:0)

<td><a href="/url/{{ $id }}"></a></td>

在web.php

Route::get('/demo/{id}', 'DemoController@index');

在DemoController.php

public function index($id)
{
   // Your code
}