如何在laravel

时间:2018-02-02 07:32:33

标签: php laravel passbook

我有这条路线: Route::post('/apns/v1/devices/{device_token}/registrations/{pass_identifier}/{pass_serial}', 'ApiController@registrations');

如何获取device_token,pass_identifier和pass_serial的值并将它们保存在我的控制器中的变量中?

例如: POST /v1/devices/3252362643/registrations/passtype.test/4312

我想获得值3252362643passtype.test4312

将它们保存在laravel控制器中的变量中。

3 个答案:

答案 0 :(得分:0)

您可以使用request()帮助程序获取路径参数:

$device_token = request()->route()->parameter('device_token')

$pass_identifier = request()->route()->parameter('pass_identifier')

$pass_serial = request()->route()->parameter('pass_serial')

答案 1 :(得分:0)

在控制器中:

public function registrations($device_token, $pass_identifier, $pass_serial)
{
   //insert to DB
   $data = new User; //your model
   $data->device_token= $device_token;
   $data->pass_identifier= $pass_identifier;
   $data->pass_serial= $pass_serial;
   $data->save();
}

答案 2 :(得分:0)

  

遵循“Ilya Yaremchuk”和“btl”方法......这个是替代方法

在这种情况下,你可以从$ ss,$ ss1,$ ss2 获得这些价值

**Add this in your laravel controller**


   $url = 'POST /v1/devices/3252362643/registrations/passtype.test/4312';
        $names = explode('/', $url);
            if (!empty($names)) {
                $ss = $names[3];
                $ss1 = $names[5];
                $ss2 = $names[6];
            }
  

或试试这个

         $names = explode('/', $_SERVER['REQUEST_URI']);
         if (!empty($names)) {
             $ss = $names[3];
             $ss1 = $names[5];
             $ss1 = $names[6];
          }