Shuvo
Shuvo

Reputation: 303

How to show data by id in laravel 5.2

I want to show data by id. If id=1 its need to show only id=1 data and if id 2 its should show only id=2 all data. My controller method:

->with('classroom',classroomModel::find($id)->first());

Here is my view:

<li>Class code-->{{$classroom->class_code}}</li>
<li>Subject-->{{$classroom->subject_name}}</li>
<li>Section-->{{$classroom->section}}</li>

now it is only show id=1 data. If i view id=2 data then it's show id=1 data. What should to do in my controller?

Upvotes: 0

Views: 959

Answers (1)

Martin
Martin

Reputation: 1279

You should pass variable to your controller's function, to do that you can make a link in your view:

<a href="{{Route('name', ['id' => 1])}}">Id 1</a>
<a href="{{Route('name', ['id' => 2])}}">Id 2</a>

Routes:

Route::get('/something/{id}', [
    'uses' => 'somecontroller@yourfunction',
    'as' => 'name'
]);

Function:

public function yourfunction($id)
{
    // you can use $id here and return view with classroom
}

I Hope this example will help you.

Upvotes: 1

Related Questions