. */ namespace App\Http\Controllers\Api\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Account; use App\AccountAction; use App\Rules\NoUppercase; class AccountActionController extends Controller { public function index(int $id) { return $this->resolveAccount($id)->actions; } public function get(int $id, int $actionId) { return $this->resolveAccount($id) ->actions() ->where('id', $actionId) ->firstOrFail(); } public function store(Request $request, int $id) { $account = $this->resolveAccount($id); $request->validate([ 'key' => ['required', 'alpha_dash', new NoUppercase], 'code' => ['required', 'alpha_num', new NoUppercase] ]); $accountAction = new AccountAction; $accountAction->account_id = $account->id; $accountAction->key = $request->get('key'); $accountAction->code = $request->get('code'); $accountAction->save(); return $accountAction; } public function update(Request $request, int $id, int $actionId) { $account = $this->resolveAccount($id); $request->validate([ 'key' => ['alpha_dash', new NoUppercase], 'code' => ['alpha_num', new NoUppercase] ]); $accountAction = $account ->actions() ->where('id', $actionId) ->firstOrFail(); $accountAction->key = $request->get('key'); $accountAction->code = $request->get('code'); $accountAction->save(); return $accountAction; } public function destroy(int $id, int $actionId) { return $this->resolveAccount($id) ->actions() ->where('id', $actionId) ->delete(); } private function resolveAccount(int $id) { $account = Account::findOrFail($id); if ($account->dtmf_protocol == null) abort(403, 'DTMF Protocol must be configured'); return $account; } }