How to pass value inside href to laravel controller?

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' => 'SwitchinfoController@switchInfo',
    'as'   => 'switch'
]);

Then in your Blade

@foreach($infolist as $info)
  <a href="{!! route('switch', ['prisw'=>$info->prisw, 'secsw'=>$info->secsw]) !!}">Link</a>
@endforeach

You can simply pass parameter in your url like

@foreach($infolist as $info)
<a href="{{ url('switchinfo/'.$info->prisw.'/'.$info->secsw.'/') }}">
{{$info->prisw}} / {{$info->secsw}}
</a>
@endforeach

and route

Route::get('switchinfo/{prisw}/{secsw}', 'SwitchinfoController@functionname');

and function in controller

public functionname($prisw, $secsw){
  // your code here
}

Name your route:

Route::get('switchinfo/{parameter}', [
     'as'=> 'test',
     'uses'=>'SwitchinfoController@function'
]);

Pass an array with the parameters you want

 <a href="{{route('test', ['parameter' => 1])}}">
    {{$info->prisw}} / {{$info->secsw}}
 </a>

and in controller function use

function ($parameter) {
   // do stuff
}

Or if don't want to bind parameter to url and want just $_GET parameter like url/?parameter=1

You may use it like this

Route::get('switchinfo', [
    'as'=> 'test', 
    'uses'=>'SwitchinfoController@function'
]);

function (){
     Input::get('parameter');
}

Docs

Tags:

Php

Laravel