PHP code example of coenond / lrvl-rspns

1. Go to this page and download the library: Download coenond/lrvl-rspns 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/ */

    

coenond / lrvl-rspns example snippets

 php
/**
 * get user by id.
 */
public function get($id)
{
    try {
        $user = User::findOrFail($id);
        return rspns_ok($user);
    } catch(ModelNotFoundException $e) {
        return rspns_not_found($id, $e->getMessage());
    }
}

/**
 * Do not create users like this in your system :)
 */
public function create(Request $request)
{
    $email = $request->input('email');
    $password = $request->input('password');

    if (User::whereEmail($email)->exists()) {
        return rspns_bad_request($request->all(), "User already exists");
    }
    
    $user = User::create(['email' => $email, 'password' => $password]);

    return rspns_created($user);
}