1. Go to this page and download the library: Download zlt/laravel-api-auth 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/ */
return [
/*
* If true, `api/login` and `api/register` routes will be registered.
*/
'shouldIncludeRoutes' => true,
/*
* Define your auth model
*/
'authUser' => App\Models\User::class,
/*
* If true, action will try to create token in registration and appending token in login.
*/
'enableSanctum' => true,
/*
* In some cases, you might want to use other column than `email`
*/
'username' => 'email',
/*
* Validation rule for password in registration
*/
'password:rule' => '
class YourService extends Zlt\LaravelApiAuth\Services\BaseService{
static function getInstance(): static
{
}
}
// Pass to constructor
static function getInstance(): static
{
return new static(YourModel::query());
}
// Inside constructor
public function __construct()
{
parent::__construct(YourModel::query());
}
// Register queryable column in constructor
class YourService extends Zlt\LaravelApiAuth\Services\BaseService{
public function __construct()
{
$this->registerQueryColumn(QueryableColumn::from(
'date', // DB Column
['startDate', 'endDate'], // Request Parameters
'date_format:Y-m-d|
public function __construct()
{
$this->registerQueryColumn(QueryableColumn::from(
'date', // DB Column
['startDate', 'endDate'], // Request Parameters
'date_format:Y-m-d|->startOfDay()->timestamp;
}
return $date->endOfDay()->timestamp;
}
));
parent::__construct(YourModel::query());
}
use Zlt\LaravelApiAuth\Utils\CanCache;
class YourClass {
use CanCache;
public function yourMethod(Request $request){
if($this->checkIfCacheKeyExists($request)){
return $this->getCacheData($request);
}
$response = $this->computeData();
$this->storeCache($request,$response);
return $response;
}
}