首页 > 解决方案 > 如何在 href 中传递 id 以使用 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

演示控制器.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);
}

网页.php

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

标签: laravel

解决方案


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

在 web.php 中

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

在 DemoController.php

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

推荐阅读