Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

oborrero's avatar

ForEach Loop with HTML Link?

Greetings,

I have a for each loop that goes through and grabs the Job Number for each job and what I would like to do is generate an HTML link that will show each job. I'm using a resource route to get jobs/{jobs}. I have Illuminate\HTML installed but I'm not sure which HTML::link* to use to define the Job Number as the link.

Here's my Loop

@foreach ($jobs as $job)
     <tr>
        <td>{{ $job->number }}</td>
     </tr>
@endforeach

Here's my Controller that goes through and get's all the jobs

 public function index()
    {
        $jobs = Job::with('customer','steps', 'poles', 'permits')->get();
        return view('jobs.home', compact ('jobs'));
    }
0 likes
8 replies
oborrero's avatar

Thanks @SachinAgarwal, could you give me an example? Do I wrap the whole TD in that code or do I modify my {{$job->number}} code?

fraserk's avatar

Here's an example.

 @foreach ($jobs as $job)
     <tr>
        <td>{{ link_to_route('routeName','anchor text', $job->number }}</td>
     </tr>
@endforeach
1 like
usman's avatar
usman
Best Answer
Level 27

@oborrero

 @foreach ($jobs as $job)
     <tr>
        <td>{!! app('html')->linkRoute('jobs.show','View Job', $job->number !!}</td>
     </tr>
@endforeach

Note: app('html')->linkRoute() is same as HTML::linkRoute().

1 like

Please or to participate in this conversation.