. */ namespace App\Http\Controllers\Admin\Account; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use App\Account; use App\AccountAction; use App\Rules\NoUppercase; class ActionController extends Controller { public function create(int $accountId) { $account = Account::findOrFail($accountId); return view('admin.account.action.create_edit', [ 'action' => new AccountAction, 'account' => $account ]); } public function store(Request $request, int $accountId) { $account = Account::findOrFail($accountId); $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(); Log::channel('events')->info('Web Admin: Account action created', ['id' => $account->identifier, 'action' => $accountAction->key]); return redirect()->route('admin.account.show', $accountAction->account)->withFragment('#actions'); } public function edit(int $accountId, int $actionId) { $account = Account::findOrFail($accountId); $accountAction = $account->actions() ->where('id', $actionId) ->firstOrFail(); return view('admin.account.action.create_edit', [ 'action' => $accountAction, 'account' => $account ]); } public function update(Request $request, int $accountId, int $actionId) { $account = Account::findOrFail($accountId); $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(); Log::channel('events')->info('Web Admin: Account action updated', ['id' => $account->identifier, 'action' => $accountAction->key]); return redirect()->route('admin.account.show', $account)->withFragment('#actions'); } public function delete(int $accountId, int $actionId) { $account = Account::findOrFail($accountId); return view('admin.account.action.delete', [ 'account' => $account, 'action' => $account->actions() ->where('id', $actionId) ->firstOrFail() ]); } public function destroy(Request $request, int $accountId, int $actionId) { $account = Account::findOrFail($accountId); $accountAction = $account->actions() ->where('id', $actionId) ->firstOrFail(); $accountAction->delete(); Log::channel('events')->info('Web Admin: Account action deleted', ['id' => $accountAction->account->identifier, 'action_id' => $accountAction->key]); return redirect()->route('admin.account.show', $accountAction->account)->withFragment('#actions'); } }