Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\Entities\ApiKey;
- use App\Events\ApiKeyActionlog;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- use App\Services\ApiKeyService;
- class ApiKeyController extends Controller
- {
- protected $apiKey;
- public function __construct(ApiKeyService $apiKey)
- {
- parent::__construct();
- $this->apiKey = $apiKey;
- }
- /*
- * ------------ GET ROUTES ------------
- */
- public function index()
- {
- event(new ApiKeyActionlog('Wyświetlenie wszystkich kluczy API', []));
- return view('crm.apiKey.index', [
- 'apiKeys' => $this->apiKey->findAll(),
- ]);
- }
- public function active()
- {
- event(new ApiKeyActionlog('Wyświetlenie aktywnych kluczy API', []));
- return view('crm.apiKey.active', [
- 'apiKeys' => $this->apiKey->findActive(),
- ]);
- }
- public function archived()
- {
- event(new ApiKeyActionlog('Wyświetlenie zarchiwizowanych kluczy API', []));
- return view('crm.apiKey.archived', [
- 'apiKeys' => $this->apiKey->findArchived(),
- ]);
- }
- public function create(ApiKey $apiKey = null)
- {
- return view('crm.apiKey.create', [
- 'apiKeyForm' => $this->formBuilder->create('ApiKeyForm')
- ]);
- }
- /*
- * ------------ POST ROUTES ------------
- */
- public function store(Request $request)
- {
- $apiKey = $this->apiKey->create($request->all());
- event(new ApiKeyActionlog('Utworzenie klucza API', ['actual' => $apiKey]));
- return $this->response(
- redirect()->route('apiKey'),
- 'Klucz API został poprawnie dodany.',
- 'success',
- ['apiKey' => $this->apiKey->findById($apiKey->id)]
- );
- }
- public function update(ApiKey $apiKey, Request $request)
- {
- $before = clone $apiKey;
- $this->apiKey->update($apiKey, $request->all());
- event(new ApiKeyActionlog('Aktualizacja klucza API', ['actual' => $apiKey, 'before' => $before]));
- return $this->response(
- redirect()->route('apiKey'),
- 'Klucz API został poprawnie zaktualizowany w bazie danych.',
- 'success',
- ['apiKey' => $apiKey]
- );
- }
- public function archive(ApiKey $apiKey)
- {
- $this->apiKey->archive($apiKey);
- event(new ApiKeyActionlog('Archiwizacja klucza API', ['actual' => $apiKey]));
- return $this->response(
- redirect()->back(),
- 'Ankieta została poprawnie zarchiwizowany.',
- 'success',
- ['apiKey' => $apiKey]
- );
- }
- public function restore(ApiKey $apiKey)
- {
- $this->apiKey->restore($apiKey);
- event(new ApiKeyActionlog('Przywrócenie klucza API', ['actual' => $apiKey]));
- return $this->response(
- redirect()->back(),
- 'Klucz API został poprawnie przywrócony.',
- 'success',
- ['apiKey' => $apiKey]
- );
- }
- public function delete(ApiKey $apiKey)
- {
- $this->apiKey->forceDelete($apiKey);
- event(new ApiKeyActionlog('Usunięcie klucza API', ['actual' => $apiKey]));
- return $this->response(
- redirect()->route('apiKey'),
- "Trwale usunąłeś klucz {$apiKey->website} z bazy danych.",
- 'info',
- ['apiKey' => $apiKey]
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment