Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- namespace App\Repositories;
- use App\Contracts\ApiKeyContract;
- use App\Entities\ApiKey;
- class ApiKeyRepository implements ApiKeyContract
- {
- /**
- * ApiKey Entity container
- *
- * @var ApiKey
- */
- protected $apiKey;
- /**
- * Answer Entity construct
- *
- * @param ApiKey $apiKey
- */
- function __construct(ApiKey $apiKey)
- {
- $this->apiKey = $apiKey;
- }
- /**
- * Return Answer model
- *
- * @return ApiKey
- */
- public function entity()
- {
- return $this->apiKey
- ->with('user');
- }
- /**
- * Find all api keys
- *
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function findAll()
- {
- return $this->entity()
- ->withTrashed()
- ->get();
- }
- /**
- * Find active api keys
- *
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function findActive()
- {
- return $this->entity()
- ->get();
- }
- /**
- * Find archived api keys
- *
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function findArchived()
- {
- return $this->entity()
- ->onlyTrashed()
- ->get();
- }
- /**
- * Find specified answer by ID
- *
- * @param integer $id
- * @return ApiKey|null
- */
- public function findById($id)
- {
- return $this->entity()
- ->whereId($id)
- ->withTrashed()
- ->first();
- }
- /**
- * Find specified answer by ID
- *
- * @param string $key
- * @return ApiKey|null
- */
- public function findByKey($key)
- {
- return $this->entity()
- ->where('key', $key)
- ->withTrashed()
- ->first();
- }
- /**
- * Create new answer and save to database
- *
- * @param array $data
- * @return ApiKey|false
- */
- public function create($data = [])
- {
- return $this->apiKey->create($data);
- }
- /**
- * Update specific recruitment
- *
- * @param ApiKey $apiKey
- * @param array $data
- * @return boolean
- */
- public function update(ApiKey $apiKey, $data = [])
- {
- return $apiKey->update($data);
- }
- /**
- * Move to archive specified recruitment (soft delete)
- *
- * @param ApiKey $apiKey
- * @return boolean
- */
- public function archive(ApiKey $apiKey)
- {
- return $apiKey->delete();
- }
- /**
- * Restore archived recruitment (soft deleted)
- *
- * @param ApiKey $apiKey
- * @return boolean
- */
- public function restore(ApiKey $apiKey)
- {
- return $apiKey->restore();
- }
- /**
- * Complete remove specific recruitment from database
- *
- * @param ApiKey $apiKey
- * @return void
- */
- public function forceDelete(ApiKey $apiKey)
- {
- $apiKey->forceDelete();
- }
- }
Add Comment
Please, Sign In to add comment