如何将路径变量值传递给模型类方法

时间:2019-03-06 02:58:53

标签: laravel jquery-ui laravel-5

在路线i中,我传递了subscription_id(http://admin.commonground.localhost/members/invite/31)。我希望此subscription_id保存在另一个表中。如何得到这个?当前没有预订ID保存在数据库中,其他值保存没有问题。请帮助

我的代码在这里

 public function send($people)
    {

        //    $subscription = new Subscription();
        //    $company = new Company();
        //   $companyUser->company()->getForeignKey(), $company->getKey()
       // $subscription_id = $this->setAttribute($subscription_id);

        try {

            foreach($people as $person) {



                $email = trim( $person['email'] );
                $name = trim( Utility::hasString(trim($person['name'])) ? $person['name'] : '');

                if(!Utility::hasString($email)){
                    continue;
                }

                $instance = new static();

                $instance->getConnection()->transaction(function () use ($instance, $email, $name) {

                    try{

                        $found = $instance->where('email', '=', $email)->first();

                        if(!is_null($found) && $found->exists){
                            $found->delete();
                        }

                        $invite_status = 'pending';
                        $subscription_id = '31';

                        $instance->setAttribute('email', $email);
                        $instance->setAttribute('name',  $name);
                        $instance->setAttribute('token', $instance->createNewToken());
                        $instance->setAttribute('subscription_id', $subscription_id );
                        $instance->setAttribute('invite_status',   $invite_status);

                        $instance->save();


                        Mail::queue(new SignupInvitationMail($instance));

                    }catch(ModelValidationException $e){



                    }catch(Exception $e){


                    }

                });

            }

        }catch (Exception $e) {

            throw $e;

        }

    }

1 个答案:

答案 0 :(得分:2)

如果您的方法是:

  

获取 http://admin.commonground.localhost/members/invite/{subscription_id}

然后您可以直接使用 subscriptionId ,如下所示:

public function yourControllerMethod($subscriptionId)
{
   // $subscriptionId = 31;
}

如果您的方法是发布方法,那么您需要将密钥定义为有效载荷,例如subscription_id => 123,然后将使用Request::Get('subscription_id')

对其进行检索。

希望这会有所帮助,谢谢