zalazdi

Untitled

Mar 8th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. <?PHP
  2.  
  3. namespace App\Repositories;
  4.  
  5. use App\Contracts\ApiKeyContract;
  6. use App\Entities\ApiKey;
  7.  
  8. class ApiKeyRepository implements ApiKeyContract
  9. {
  10.     /**
  11.      * ApiKey Entity container
  12.      *
  13.      * @var ApiKey
  14.      */
  15.     protected $apiKey;
  16.  
  17.     /**
  18.      * Answer Entity construct
  19.      *
  20.      * @param ApiKey $apiKey
  21.      */
  22.     function __construct(ApiKey $apiKey)
  23.     {
  24.         $this->apiKey = $apiKey;
  25.     }
  26.  
  27.     /**
  28.      * Return Answer model
  29.      *
  30.      * @return ApiKey
  31.      */
  32.     public function entity()
  33.     {
  34.         return $this->apiKey
  35.             ->with('user');
  36.     }
  37.  
  38.     /**
  39.      * Find all api keys
  40.      *
  41.      * @return \Illuminate\Database\Eloquent\Collection
  42.      */
  43.     public function findAll()
  44.     {
  45.         return $this->entity()
  46.             ->withTrashed()
  47.             ->get();
  48.     }
  49.  
  50.     /**
  51.      * Find active api keys
  52.      *
  53.      * @return \Illuminate\Database\Eloquent\Collection
  54.      */
  55.     public function findActive()
  56.     {
  57.         return $this->entity()
  58.             ->get();
  59.     }
  60.  
  61.     /**
  62.      * Find archived api keys
  63.      *
  64.      * @return \Illuminate\Database\Eloquent\Collection
  65.      */
  66.     public function findArchived()
  67.     {
  68.         return $this->entity()
  69.             ->onlyTrashed()
  70.             ->get();
  71.     }
  72.  
  73.     /**
  74.      * Find specified answer by ID
  75.      *
  76.      * @param integer $id
  77.      * @return ApiKey|null
  78.      */
  79.     public function findById($id)
  80.     {
  81.         return $this->entity()
  82.             ->whereId($id)
  83.             ->withTrashed()
  84.             ->first();
  85.     }
  86.  
  87.     /**
  88.      * Find specified answer by ID
  89.      *
  90.      * @param string $key
  91.      * @return ApiKey|null
  92.      */
  93.     public function findByKey($key)
  94.     {
  95.         return $this->entity()
  96.             ->where('key', $key)
  97.             ->withTrashed()
  98.             ->first();
  99.     }
  100.  
  101.     /**
  102.      * Create new answer and save to database
  103.      *
  104.      * @param array $data
  105.      * @return ApiKey|false
  106.      */
  107.     public function create($data = [])
  108.     {
  109.         return $this->apiKey->create($data);
  110.     }
  111.  
  112.     /**
  113.      * Update specific recruitment
  114.      *
  115.      * @param ApiKey $apiKey
  116.      * @param array $data
  117.      * @return boolean
  118.      */
  119.     public function update(ApiKey $apiKey, $data = [])
  120.     {
  121.         return $apiKey->update($data);
  122.     }
  123.  
  124.     /**
  125.      * Move to archive specified recruitment (soft delete)
  126.      *
  127.      * @param ApiKey $apiKey
  128.      * @return boolean
  129.      */
  130.     public function archive(ApiKey $apiKey)
  131.     {
  132.         return $apiKey->delete();
  133.     }
  134.  
  135.     /**
  136.      * Restore archived recruitment (soft deleted)
  137.      *
  138.      * @param ApiKey $apiKey
  139.      * @return boolean
  140.      */
  141.     public function restore(ApiKey $apiKey)
  142.     {
  143.         return $apiKey->restore();
  144.     }
  145.  
  146.     /**
  147.      * Complete remove specific recruitment from database
  148.      *
  149.      * @param ApiKey $apiKey
  150.      * @return void
  151.      */
  152.     public function forceDelete(ApiKey $apiKey)
  153.     {
  154.         $apiKey->forceDelete();
  155.     }
  156. }
Add Comment
Please, Sign In to add comment