简体   繁体   中英

How to pass pass data via href on Laravel?

How can I make the list link to other pages?

在此处输入图片说明

Pscontroller:

  public function show()
  {
      $ps = DB::table('ps')->get();

      return view('viewps', ['ps' => $ps]);

  }

public function view($id)
{
        $ps = Ps::find($id);

        // show the view and pass to it
        return view ('view')->with('ps', $ps);

}

routes:

Route::get('/viewps', 'PsController@show');
Route::get('/viewps/{id}', 'PsController@view');
<a href={{ route('/viewps/'.$single_ps->id)}}

Give name to route like below

Route::get('/viewps/{id}', 'PsController@view')->name('viewps');

Now wherever you wanna generate link do like this

<a href={{ route('viewps',['id'=>$single_ps->id])}}

In this way if you change endpoint of route you have not to change the router path in all files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM