1. Go to this page and download the library: Download vzool/api-hmac-guard 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/ */
use Vzool\ApiHmacGuard\Models\Mixins\Apikeyable;
class User extends Model
{
use Apikeyable;
...
}
// Get the API keys of the object
$user->apiKeys();
// Create an API key for the object
$user->createApiKey();
$apiKey = Vzool\ApiHmacGuard\Models\ApiKey::make()
// Attach a model to the API key
$apiKey = Vzool\ApiHmacGuard\Models\ApiKey::make($model)
$apiKey->clientKeys()
Route::middleware(['auth.apikey'])->get('/test', function (Request $request) {
return $request->user(); // Returns the associated model to the API key
});
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
protected $fillable = [
'name',
];
}
use Vzool\ApiHmacGuard\Http\Controllers\ApiGuardController;
use App\Transformers\BookTransformer;
use App\Book;
class BooksController extends ApiGuardController
{
public function all()
{
$books = Book::all();
return $this->response->withCollection($books, new BookTransformer);
}
}
use League\Fractal\TransformerAbstract;
use App\Book;
class BookTransformer extends TransformerAbstract
{
public function transform(Book $book)
{
return [
'id' => $book->id,
'name' => $book->name,
'created_at' => $book->created_at,
'updated_at' => $book->updated_at,
];
}
}
use Vzool\ApiHmacGuard\Http\Requests\ApiGuardFormRequest;
class BookStoreRequest extends ApiGuardFormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => '
use Vzool\ApiHmacGuard\Http\Controllers\ApiGuardController;
use App\Transformers\BookTransformer;
use App\Book;
class BooksController extends ApiGuardController
{
public function store(BookStoreRequest $request)
{
// Request should already be validated
$book = Book::create($request->all())
return $this->response->withItem($book, new BookTransformer);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.