Support the ongoing development of Laravel.io →
posted 11 years ago
Views

I am building my first website in Laravel. In this website I am showing a portfolio of several projects. I want to hyperlink every image in the portfolio to a single view of that project. But I have no idear how to acomplish this.

What I have so far:

//view
@foreach($project as $project)
<a href="/single/{{$project->id}}">
{{ HTML::image($project->image) }}
</a>

//route
Route::get('single/{project}', 'PortfolioController@getView');

//controler
public function getView($id){
return View::make('single')->with('project', Project::find($id));
}

This doesn't work. Can anyone tell me how to do this right? Thanks

Last updated 3 years ago.
0

For your controller I suppose you get all your projects like this

return View::make('')->with('projects', $projects); // Just as example

And in the view you should do

@foreach ( $projects as $project )
<a href="{{ route('project.show', $project->id) }}">{{ HTML::image($project->image) }}</a>
@endforeach

And in route you can do this

Route::get('project/{id}', array('as' => 'project.show', 'uses' => 'PortfolioController@show'));

For the show controller

public function show($id) {
    $project = Project::find($id);

    return View::make('')->with('project', $project);
}
Last updated 3 years ago.
0

It works! Thank you very much.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jonaweb jonaweb Joined 22 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.