编辑个人资料不起作用:/ laravel 7
edit profile dont worked :/ laravel 7
我想在 laravel 中编辑个人资料时遇到问题。当我单击按钮更新配置文件时出现此错误:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
此路由不支持 PATCH 方法。支持的方法:GET、HEAD。
http://127.0.0.1:8000/profile
edit.blade.php
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
Update Profile
</div>
<div class="card-body">
<form method="POST" action="{{ route('profile.edit') }}">
@method('patch')
@csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name', $user->name) }}" autocomplete="name" autofocus>
@error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row">
<label for="pseudo" class="col-md-4 col-form-label text-md-right">{{ __('pseudo') }}</label>
<div class="col-md-6">
<input id="pseudo" type="text" class="form-control @error('pseudo') is-invalid @enderror" name="pseudo" value="{{ old('pseudo', $user->pseudo) }}" autocomplete="pseudo" autofocus>
@error('pseudo')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email', $user->email) }}" autocomplete="email">
@error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Update Profile
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
web.php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/chats', 'ChatController@index')->name('chats');
Route::get('/messages', 'ChatController@fetchAllMessages');
Route::get('/messages', 'ChatController@sendMessage');
Route::get('/contacts', 'ContactsController@get');
Route::get('/conversation/{id}', 'ContactsController@getMessagesFor');
Route::get('/conversation/send', 'ContactsController@send');
Route::group(['middleware' => 'auth'], function () {
Route::get('profile', 'ProfileController@edit')->name('profile.edit');
});
配置文件控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProfileController extends Controller
{
/**
* Show the update profile page.
*
* @param Request $request
* @return \Illuminate\Contracts\Support\Renderable
*/
public function edit(Request $request)
{
return view('profile.edit', [
'user' => $request->user()
]);
}
}
有人可以帮助解决这个错误。我不明白这是什么问题。
passwordChange.blade.php 我创建此页面是为了尝试更改密码是否有效,在其他页面中它有效,但是当我在编辑配置文件中的一个页面中尝试时,却不起作用。
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Laravel - Change Password with Current</div>
<div class="card-body">
<form method="POST" action="{{ route('profile') }}">
@csrf
@foreach ($errors->all() as $error)
<p class="text-danger">{{ $error }}</p>
@endforeach
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Current Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="current_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Password</label>
<div class="col-md-6">
<input id="new_password" type="password" class="form-control" name="new_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Confirm Password</label>
<div class="col-md-6">
<input id="new_confirm_password" type="password" class="form-control" name="new_confirm_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
Update Password
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
当我尝试在不同的页面中执行此操作时,它成功了,我创建了其他页面 changePassword.blade.php,当我在此页面中更改密码时,它成功了,当我尝试更新配置文件时,当我离开密码路由等时。 .. 它也有效,但是当我想在一页中更改所有内容时,出现此错误
Facade\Ignition\Exceptions\ViewException
未定义变量:用户(视图:/home/mokoch/Bureau/projetabonnementpayant/resources/views/profile/edit.blade.php)
http://127.0.0.1:8000/profile
如果有人能帮我解决这个错误
你路由中的这一行,表示它只是一个 GET 请求
Route::get('profile', 'ProfileController@edit')->name('profile.edit');
您的表单显示 method="POST"
您可以将您的路线更改为“任何”,这将允许获取和 post
Route::any('profile', 'ProfileController@edit')->name('profile.edit');
问题出在您的表单中,您告诉 Laravel 这是包含此行的补丁程序请求
@method('patch')
但是在你的路由文件中你只是在寻找一个 get 方法
Route::get('profile', 'ProfileController@edit')->name('profile.edit');
如果您要作为补丁发送,则需要额外一行
Route::patch('profile', 'ProfileController@update');
然后您需要在您的控制器中创建一个更新方法来处理保存逻辑
public function update(Request $request)
{
// Logic to update
}
我想在 laravel 中编辑个人资料时遇到问题。当我单击按钮更新配置文件时出现此错误:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
此路由不支持 PATCH 方法。支持的方法:GET、HEAD。
http://127.0.0.1:8000/profile
edit.blade.php
@section('content') <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card"> <div class="card-header"> Update Profile </div> <div class="card-body"> <form method="POST" action="{{ route('profile.edit') }}"> @method('patch') @csrf <div class="form-group row"> <label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label> <div class="col-md-6"> <input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name', $user->name) }}" autocomplete="name" autofocus> @error('name') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="form-group row"> <label for="pseudo" class="col-md-4 col-form-label text-md-right">{{ __('pseudo') }}</label> <div class="col-md-6"> <input id="pseudo" type="text" class="form-control @error('pseudo') is-invalid @enderror" name="pseudo" value="{{ old('pseudo', $user->pseudo) }}" autocomplete="pseudo" autofocus> @error('pseudo') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="form-group row"> <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label> <div class="col-md-6"> <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email', $user->email) }}" autocomplete="email"> @error('email') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="form-group row mb-0"> <div class="col-md-6 offset-md-4"> <button type="submit" class="btn btn-primary"> Update Profile </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection
web.php
use Illuminate\Support\Facades\Route; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); Auth::routes(); Route::get('/home', 'HomeController@index')->name('home'); Route::get('/chats', 'ChatController@index')->name('chats'); Route::get('/messages', 'ChatController@fetchAllMessages'); Route::get('/messages', 'ChatController@sendMessage'); Route::get('/contacts', 'ContactsController@get'); Route::get('/conversation/{id}', 'ContactsController@getMessagesFor'); Route::get('/conversation/send', 'ContactsController@send'); Route::group(['middleware' => 'auth'], function () { Route::get('profile', 'ProfileController@edit')->name('profile.edit'); });
配置文件控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProfileController extends Controller
{
/**
* Show the update profile page.
*
* @param Request $request
* @return \Illuminate\Contracts\Support\Renderable
*/
public function edit(Request $request)
{
return view('profile.edit', [
'user' => $request->user()
]);
}
}
有人可以帮助解决这个错误。我不明白这是什么问题。
passwordChange.blade.php 我创建此页面是为了尝试更改密码是否有效,在其他页面中它有效,但是当我在编辑配置文件中的一个页面中尝试时,却不起作用。
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Laravel - Change Password with Current</div>
<div class="card-body">
<form method="POST" action="{{ route('profile') }}">
@csrf
@foreach ($errors->all() as $error)
<p class="text-danger">{{ $error }}</p>
@endforeach
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Current Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="current_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Password</label>
<div class="col-md-6">
<input id="new_password" type="password" class="form-control" name="new_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Confirm Password</label>
<div class="col-md-6">
<input id="new_confirm_password" type="password" class="form-control" name="new_confirm_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
Update Password
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
当我尝试在不同的页面中执行此操作时,它成功了,我创建了其他页面 changePassword.blade.php,当我在此页面中更改密码时,它成功了,当我尝试更新配置文件时,当我离开密码路由等时。 .. 它也有效,但是当我想在一页中更改所有内容时,出现此错误
Facade\Ignition\Exceptions\ViewException 未定义变量:用户(视图:/home/mokoch/Bureau/projetabonnementpayant/resources/views/profile/edit.blade.php) http://127.0.0.1:8000/profile
如果有人能帮我解决这个错误
你路由中的这一行,表示它只是一个 GET 请求
Route::get('profile', 'ProfileController@edit')->name('profile.edit');
您的表单显示 method="POST"
您可以将您的路线更改为“任何”,这将允许获取和 post
Route::any('profile', 'ProfileController@edit')->name('profile.edit');
问题出在您的表单中,您告诉 Laravel 这是包含此行的补丁程序请求
@method('patch')
但是在你的路由文件中你只是在寻找一个 get 方法
Route::get('profile', 'ProfileController@edit')->name('profile.edit');
如果您要作为补丁发送,则需要额外一行
Route::patch('profile', 'ProfileController@update');
然后您需要在您的控制器中创建一个更新方法来处理保存逻辑
public function update(Request $request)
{
// Logic to update
}