. */ 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 Account::findOrFail($id)->actions; } public function get(int $id, int $actionId) { return Account::findOrFail($id) ->actions() ->where('id', $actionId) ->firstOrFail(); } public function store(Request $request, int $id) { $request->validate([ 'key' => ['required', 'alpha_dash', new NoUppercase], 'code' => ['required', 'alpha_num', new NoUppercase], 'protocol' => 'required|in:sipinfo,rfc2833' ]); $accountAction = new AccountAction; $accountAction->account_id = Account::findOrFail($id)->id; $accountAction->key = $request->get('key'); $accountAction->code = $request->get('code'); $accountAction->protocol = $request->get('protocol'); $accountAction->save(); return $accountAction; } public function update(Request $request, int $id, int $actionId) { $request->validate([ 'key' => ['alpha_dash', new NoUppercase], 'code' => ['alpha_num', new NoUppercase], 'protocol' => 'in:sipinfo,rfc2833' ]); $accountAction = Account::findOrFail($id) ->actions() ->where('id', $actionId) ->firstOrFail(); $accountAction->key = $request->get('key'); $accountAction->code = $request->get('code'); $accountAction->protocol = $request->get('protocol'); $accountAction->save(); return $accountAction; } public function destroy(int $id, int $actionId) { return Account::findOrFail($id) ->actions() ->where('id', $actionId) ->delete(); } }