PHP code example of gelgoog135 / laravel-jsend

1. Go to this page and download the library: Download gelgoog135/laravel-jsend 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/ */

    

gelgoog135 / laravel-jsend example snippets


public function create(Request $request)
{
  $userData = $request->input('data');
  if (empty($userData['email']))
      return jsend_fail(['email' => 'Email is  '.$e->getMessage());
  }
}

class Handler extends ExceptionHandler
{
    use Shalvah\LaravelJsend\JsendExceptionFormatter;
    
    // ...
}

return jsend_success([
  "id" => 2,
  "title" => "New life",
  "body" => "Trust me, this is great!"
]);

$post = Post::find($id);
return jsend_success($post);

return jsend_fail([
    "title" => "title is "
]);

return jsend_error("Unable to connect to database");

return jsend_error("Unable to connect to database", 'E0001', ['type' => 'database error']);

return jsend_success($post, 201, ["X-My-Header" => "header value"]);
return jsend_fail(["location_id" => "Location not found"], 404);
return jsend_error("Unable to connect to database", 'E0001', [], 503, ["X-My-Header" => "header value"]);