Ad

Laravel: How To Pass Data From Controller To Repository

- 1 answer

Can anyone help me, I would like to pass id to my repository. the output is illegal offstring id thanks for your response!

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;
    }
Ad

Answer

When you do this you are storing the id value, not an array:

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

So in this case $data holds the actual 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'];

Ad
source: stackoverflow.com
Ad