将数据表单视图传递到控制器枪口Laravel 5

时间:2018-07-30 07:49:57

标签: php laravel api guzzle6

当我用火发送数据时,我尝试使用食尸鬼,总是出现导致

  

500内部服务器错误

这是我正在执行的代码:

查看

<form action="{{URL(route('coba.index'))}}" method="POST">
    <div class="row">
        <div class="col m6">
            <div class="row">
                <div class="input-field col s12">
                    {{ csrf_field() }}
                    <label for="promoname">Promo Name</label>
                    <input id="promoname" name="promoName" type="text">
                </div>
                <div class="input-field col s12">
                    <label for="promocode">Promo Code</label>
                    <input id="promocode" name="promoCode" type="text">
                </div>
</form>

控制器

<?php
    namespace App\Http\Controllers;
    use GuzzleHttp\Client;
    class GuzzleController extends Controller
    {
        public function getRemoteData(){            
            $client = new Client;            
            $data = Input::all();
            $promo_name=$data['promoName'];
            $promo_code=$data['promoCode'];

            $url = "http://192.168.0.41:88/API_CmsDeveloop/public/api/v1/price-rules/store";
            $request = $client->post($url, [
                'form_params' => [
                    "promo_name" => $promo_name,
                    "promo_code" => $promo_code
                    ]
            ]);            
            echo '<pre>';
            print_r($request );
        }
    }

路线

Route::post('/cobaGuzzle','GuzzleController@getRemoteData')->name('coba.index');

有人知道我的错误吗?

1 个答案:

答案 0 :(得分:0)

密码:{!! csrf_field() !!}在表单内。 并检查。谢谢