PHP code example of haxneeraj / laravel-api-kit
1. Go to this page and download the library: Download haxneeraj/laravel-api-kit 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/ */
haxneeraj / laravel-api-kit example snippets
use Haxneeraj\LaravelAPIKit\Traits\APIResponseTrait;
class ExampleController extends Controller
{
use APIResponseTrait;
public function index()
{
return $this->response(true, 'Data fetched successfully', ['key' => 'value']);
}
public function store(Request $request)
{
$user = User::create([
//data
]);
return $this->responseCreated('Resource created successfully', $user);
}
public function delete(User $user)
{
$user->delete();
return $this->responseDeleted('Resource deleted successfully');
}
}