Der PATCH-Methode ist der Zugriff auf Rollenrouten nicht gestattet. Unterstützt nur GET-, HEAD- und POST-Methoden
P粉986028039
P粉986028039 2023-08-15 19:45:00
0
1
631
<p>Ich möchte Spatie Laravel verwenden, um Rollen und Berechtigungen zu erstellen. Ich kann meinen Charakter aufgrund eines Fehlers nicht bearbeiten: </p> <blockquote> <p>Das Rollenrouting der PATCH-Methode wird nicht unterstützt. Unterstützte Methoden sind: GET, HEAD, POST. </p> </blockquote> <p><strong>Controller: </strong></p> <pre class="brush:php;toolbar:false;">public function edit(string $id) { $role = Role::find($id); $permission = Permission::get(); $rolePermissions = DB::table("role_has_permissions")->where("role_has_permissions.role_id",$id) ->pluck('role_has_permissions.permission_id','role_has_permissions.permission_id') ->all(); return view('roles.edit',compact('role','permission','rolePermissions')); } öffentliche Funktionsaktualisierung (Request $request, string $id) { $this->validate($request, [ 'name' => 'erforderlich', 'permission' => 'erforderlich', ]); $role = Role::find($id); $role->name = $request->input('name'); $role->save(); $role->syncPermissions($request->input('permission')); Return Redirect()->route('roles.index') ->with('success','Rollenaktualisierung erfolgreich'); }</pre> <p><strong>Blade-Vorlage:</strong></p> <pre class="brush:php;toolbar:false;"><form action='{{ url('roles/') }}' method='post'> @csrf @method('PUT') <div class="my-3 p-3 bg-body abgerundeter schatten-sm"> <a href='{{ url('roles') }}' class="btn btn-secondary">Return</a> {!! Form::model($role, ['method' => 'PATCH','route' => ['roles.update', $role->id]]) !!} <div class="mb-3 row"> <label for="permission" class="col-sm-2 col-form-label">Permission</label> <div class="col-sm-10"> {{-- <input type="text" class="form-control" name='permission' value="{{ $role->permission }}" id="permission"> {!! Form::text('name', null, array('placeholder' => 'name','class' => 'form-control')) !!} </div> </div></pre> <p><strong>路由:</strong></p> <pre class="brush:php;toolbar:false;">Route::group(['middleware' => ['auth']], function() { Route::resource('admin', adminController::class); Route::resource('produk', produkController::class); Route::resource('roles', roleController::class); });</pre> <p><br /></p>
P粉986028039
P粉986028039

Antworte allen(1)
P粉245276769

在编辑视图中的HTML表单中添加@method('PUT')指令。通常情况下,PUT方法用于在RESTful API中更新资源,Laravel会自动将其视为PATCH请求。

<form action="{{ route('roles.update', $role->id) }}" method="POST">
    @method('PUT')
    @csrf
    <div class="my-3 p-3 bg-body rounded shadow-sm">
        <a href="{{ route('roles.index') }}" class="btn btn-secondary">返回</a>
        <div class="mb-3 row">
            <label for="permission" class="col-sm-2 col-form-label">权限</label>
            <div class="col-sm-10">
                {!! Form::text('permission', null, array('placeholder' => '权限名称', 'class' => 'form-control')) !!}
            </div>
        </div>
    </div>
    <button type="submit">更新角色</button>
</form>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage