PHP code example of pedre / response

1. Go to this page and download the library: Download pedre/response library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pedre / response example snippets


  $response = new Response();

  // set boolean 'success'. It's optional (default is true)
  $response->setSuccess();

  // set array 'data'. It's optional (default is empty array)
  $response->setData();

  // set array 'message'. It's optional (default is empty string)
  $response->setMessage();

  // set integer 'error_code'. It's optional
  $response->setErrorCode();

  // set integer 'status'. It's optional (default is 200)
  $response->setStatus();

  // send json response. It's 

use Pedre\Response\Response;

class UserController extends Controller
{
   public function login(Request $request,Response $response){
        $validator = Validator::make($input, [
            'email' => '     ->setErrorCode(400)
                ->setData(['errorMessages'=>$validator->messages()])
                ->send();
        }

        if (Auth::attempt(['email' => $input['email'], 'password' => $input['password']],'web')) {
            return  $response->setMessage('Successful Login, Congratulations !!!')->send();
        }
        else{
            return  $response->setSuccess(false)
                ->setMessage('There is not any user, Please register')
                ->send();
        }

   }
}