-
resources/views/users/edit.blade.php
Open in GitHub@extends('users.layout', ['tab' => 'profile']) @section('main_content') <div class="card"> <div class="card-body"> <h1>@lang('users.profile')</h1> <hr class="my-4"> {!! Form::model($user, ['method' => 'PATCH', 'route' => ['users.update']]) !!} <div class="form-group row"> {!! Form::label('name', __('users.attributes.name'), ['class' => 'col-sm-2 col-form-label']) !!} <div class="col-sm-5"> {!! Form::text('name', null, ['class' => 'form-control' . ($errors->has('name') ? ' is-invalid' : ''), 'placeholder' => __('users.placeholder.name'), 'required']) !!} @error('name') <span class="invalid-feedback">{{ $message }}</span> @enderror </div> </div> <div class="form-group row"> {!! Form::label('email', __('users.attributes.email'), ['class' => 'col-sm-2 col-form-label']) !!} <div class="col-sm-5"> {!! Form::text('email', null, ['class' => 'form-control' . ($errors->has('email') ? ' is-invalid' : ''), 'placeholder' => __('users.placeholder.email'), 'required']) !!} @error('email') <span class="invalid-feedback">{{ $message }}</span> @enderror </div> </div> <div class="form-group offset-sm-2"> {!! Form::submit(__('forms.actions.save'), ['class' => 'btn btn-success']) !!} </div> {!! Form::close() !!} </div> </div> @endsection
-
routes/web.php
Open in GitHubuse Illuminate\Support\Facades\Route; // Route::resource('users', 'UserController')->only('show'); //
-
app/Http/Controllers/UserController.php
Open in GitHubuse App\Http\Requests\UsersRequest; use App\Models\Role; use App\Models\User; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; class UserController extends Controller { // public function edit(): View { $user = auth()->user(); $this->authorize('update', $user); return view('users.edit', [ 'user' => $user, 'roles' => Role::all() ]); } public function update(UsersRequest $request): RedirectResponse { $user = auth()->user(); $this->authorize('update', $user); $user->update($request->validated()); return redirect()->route('users.edit')->withSuccess(__('users.updated')); } }