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
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);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community