Ad

How To Pass Value Inside Href To Laravel Controller?

- 1 answer

This is code snippet from my view file.

@foreach($infolist as $info)
 <a target="_blank" rel="nofollow noreferrer" href="">{{$info->prisw}} / {{$info->secsw}}</a>
@endforeach

Here is my route which I defined inside route file

Route::get('switchinfo','SwitchinfoController');

I want to pass two values inside href tag to above route and retrieve them in controller. Can someone provide code to do this thing?

Ad

Answer

Since you are trying to pass two parameters to your controller,

You controller could look like this:

<?php namespace App\Http\Controllers;

class SwitchinfoController extends Controller{

    public function switchInfo($prisw, $secsw){
       //do stuffs here with $prisw and $secsw
    }
}

Your router could look like this

$router->get('/switchinfo/{prisw}/{secsw}',[
    'uses' => '[email protected]',
    'as'   => 'switch'
]);

Then in your Blade

@foreach($infolist as $info)
  <a target="_blank" rel="nofollow noreferrer" href="{!! route('switch', ['prisw'=>$info->prisw, 'secsw'=>$info->secsw]) !!}">Link</a>
@endforeach
Ad
source: stackoverflow.com
Ad