简体   繁体   English

Laravel:如何将数据从控制器传递到存储库

[英]Laravel: how to pass data from controller to repository

Can anyone help me, I would like to pass id to my repository. 谁能帮我,我想将ID传递到我的存储库。 the output is illegal offstring id thanks for your response! 输出为illegal offstring id感谢您的回复!

this is my controller 这是我的控制器

public function delete()
{
   $response = ['status' => false, 'message' => 'Invalid request'];
     if (Request::ajax()) {

        if (Request::isMethod('POST')) {

        $data = Request::input('id');

        $response = $this->testRepo->delete($data);

        }
    }

   return Response::json($response);

}

this is my testRepo->delete 这是我的测试回购->删除

public function delete($data) 
    {
        $data = $data['id'];

        $result = DB::table('user_details')
        ->select('id')
        ->where('id', '=',$data);

        if ($result) {
                    // delete 
        }

        return $response;
    }

When you do this you are storing the id value, not an array: 执行此操作时,将存储id值,而不是数组:

$data = Request::input('id');

So in this case $data holds the actual id. 因此,在这种情况下, $data保存实际的ID。

If you want to send the entire input array you can do that like this: 如果要发送整个输入数组,可以这样进行:

$data = Request::all();

Then retrieve it like this: 然后像这样检索它:

$id = $data['id'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM