Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass value inside href to laravel controller?

Tags:

php

laravel

This is code snippet from my view file.

@foreach($infolist as $info)
 <a 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?

like image 375
ShanWave007 Avatar asked Jan 15 '16 11:01

ShanWave007


1 Answers

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
like image 60
Emeka Mbah Avatar answered Sep 26 '22 02:09

Emeka Mbah