. */ namespace App\Http\Controllers\Api\Admin; use App\Http\Controllers\Controller; use App\Account; use App\AccountDictionaryEntry; use Illuminate\Http\Request; class AccountDictionaryController extends Controller { public function index(Request $request, int $accountId) { return Account::findOrFail($accountId)->dictionary; } public function show(Request $request, int $accountId, string $key) { return Account::findOrFail($accountId)->dictionaryEntries()->where('key', $key)->first(); } public function set(Request $request, int $accountId, string $key) { $request->validate([ 'value' => 'required' ]); $entry = Account::findOrFail($accountId)->dictionaryEntries()->where('key', $key)->first(); if (!$entry) { $entry = new AccountDictionaryEntry; } $entry->account_id = $accountId; $entry->key = $key; $entry->value = $request->get('value'); $entry->save(); return $entry; } public function destroy(Request $request, int $accountId, string $key) { return Account::findOrFail($accountId)->dictionaryEntries()->where('key', $key)->delete(); } }