Php 从窗体向Laravel中的控制器发送隐藏输入

Php 从窗体向Laravel中的控制器发送隐藏输入,php,laravel,laravel-5,laravel-5.1,blade,Php,Laravel,Laravel 5,Laravel 5.1,Blade,我有一个 创建表单 我正在尝试将{!!Form::hidden('$id',$account->account_id)!!传递给我的存储控制器,以便我可以在控制器中的store()函数中访问它 但是我一直得到未定义的变量:id 有人能告诉我从表单向控制器发送隐藏输入的正确方法吗?您的代码有两个问题: 您的隐藏输入应该使用id,而不是$id 您的存储方法应该使用$inputs['id'],而不是直接访问$id 您尚未向我们显示控制器的存储方法中的代码。id位于$inputs['id']中,它工作

我有一个

创建表单
我正在尝试将
{!!Form::hidden('$id',$account->account_id)!!
传递给我的存储控制器,以便我可以在控制器中的
store()函数中访问它

但是我一直得到
未定义的变量:id


有人能告诉我从表单向控制器发送隐藏输入的正确方法吗?

您的代码有两个问题:

  • 您的隐藏输入应该使用
    id
    ,而不是
    $id
  • 您的
    存储
    方法应该使用
    $inputs['id']
    ,而不是直接访问
    $id

  • 您尚未向我们显示控制器的
    存储
    方法中的代码。id位于
    $inputs['id']
    中,它工作正常。你应该回答。我会接受的。:)
    {!! Form::open(array('url' => '/cpe/store', 'class' => 'form-horizontal', 'role' =>'form')) !!}
    
                  <h3 class="nomargin">Create CPE </h3>
    
                  <div class="mb10">
                      <label class="control-label">Account ID </label>
                      <input type="text" class="form-control" name="account_id" value="{{$account->account_id}}">
                  </div>
    
              
                  <div class="mb10">
                      <label class="control-label">Max Up</label>
                      <input type="text" class="form-control" name="max_up" value="30000">
                  </div>
    
                  <div class="mb10">
                      <label class="control-label">Max Down</label>
                      <input type="text" class="form-control" name="max_down" value="50000" >
                  </div>
    
    
    
                  <a href="/account/" class="btn btn-danger ">Go back to account </a>
    
                  {!! Form::hidden('$id', $account->account_id )!!}
    
                  <button type="submit" class="btn btn-success ">Create</button>
    
    
                {!! Form::close();!!}
    
    public function store() {
    
            $inputs = Input::all();
            unset($inputs['_token']);
          
    
            $cpe_mac = $inputs['mac1'].$inputs['mac2'].$inputs['mac3'].$inputs['mac4'].$inputs['mac5'].$inputs['mac6'];
    
            $cpe = [];
    
            $cpe['cpe_mac'] = $cpe_mac;
            $cpe['bandwidth_max_up'] = (int)$inputs['max_up'];
            $cpe['bandwidth_max_down'] = (int)$inputs['max_down'];
    
            $json = json_encode($cpe);
    
            try {
    
                $url = 'http://172.16.139.129:1234/vse/vcpe';
                $ch = curl_init($url);
    
                if (FALSE === $ch)
                    throw new Exception('failed to initialize');
    
                curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
                curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
                curl_setopt($ch, CURLOPT_TIMEOUT, 1);
                $result = curl_exec($ch);
                curl_close($ch);
    
                if (FALSE === $result)
                    throw new Exception(curl_error($ch), curl_errno($ch));
    
                // ...process $result now
            } catch(Exception $e) {
    
                trigger_error(sprintf(
                    'Curl failed with error #%d: %s',
                    $e->getCode(), $e->getMessage()),
                    E_USER_ERROR);
    
            }
    
            $result_json =  json_decode($result, true);
    
    
            dd($id); // Undefined variable: id
    
    
            if ( $result_json['status'] == '200') {
                return Redirect::to('/account/'.$id.'#hardware') ->with('success','The CPE was created succesfully!');
            } else {
                return Redirect::to('/account/'.$id.'#hardware') ->with('error', $result_json['message']);
            }
    
        }