i have problem, when i want to edit my profile in laravel. When i click button update profile have this error :
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The PATCH method is not supported for this route. Supported methods: 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'); });
Profile controller:
<?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()
]);
}
}
someone can help resolve this error pls. I don't understand what is the problem.
passwordChange.blade.php i created this page for try if change password worked and in other page it's worked but when i try in one page in edit profile, dont worked.
@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
When i try to do this in differents pages it's worked, i created other page changePassword.blade.php and when i change password in this page its worked, and when i try update profile when i leave password route etc... its worked too, but when i want to change all in one page i have this error
Facade\Ignition\Exceptions\ViewException Undefined variable: user (View: /home/mokoch/Bureau/projetabonnementpayant/resources/views/profile/edit.blade.php) http://127.0.0.1:8000/profile
If someone can help me resole this error