I'm new to Laravel (I'm using version 8) and I've been reviewing this error for a long time and I don't know what else to try. I have a resource controller called ** UserController.php ** and I set the path in ** web.php ** as follows: Route::resource('usuarios', App\Http\Controllers\UsuarioController::class);
The user can enter their profile and modify their fields through this menu option that invokes the edit() method of the controller:
So far everything works very well, but when the user enters to edit in the ** edit.blade.php ** form, and selects the "update" button that calls the method ** update () ** of the controller, it jumps to me the error: BadMethodCallException Method App\Http\Controllers\UsuarioController::update does not exist.
This is edit.blade.php:
@section('title', 'Mi Perfil')
@section('intro')
@endsection
<br><br>
<style type="text/css">
h5 {text-align: center}
nav.navbar {
background-color: #34495E;
}
</style>
@section('content0')
<div class="container3">
<div class="bShadow3 bShadow-33">
<form method="POST" action="{{route('usuarios.update',[Auth::user()->slug]) }}">
@method('PUT')
@csrf
<br>
<h5>Mi perfil</h5>
<div class="form-group ml-5 mr-5">
<label for="name">{{ __('Nombre de usuario') }}</label>
<input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{Auth::user()->name}}" autocomplete="name" maxlength="30" autofocus placeholder="Introduce tu nombre de usuario" required>
@error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="form-group ml-5 mr-5">
<label for="name">{{ __('Dirección de correo:') }}</label><br>
<label for="email">{{Auth::user()->email}}</label>
</div>
<div class="form-group row mb-0">
<div class="col text-center">
<button type="submit" class="btn2 mt-2 mb-3">
{{ __('Actualizar') }}
</button>
<button type="default" class="btn2 mt-2 mb-3">
{{ __('Cancelar') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
This is UsuarioController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use App\Models\Role;
class UsuarioController extends Controller
{
public function __construct()
{
//permitir solo usuarios autenticados
$this->middleware('auth');
}
public function index()
{
//
}
public function create()
{
//
}
public function store(Request $request)
{
}
public function show($id)
{
}
public function edit($id)
{
$usuario=User::find($id);
if ($usuario== null)
return Redirect::to('usuario');
return view('usuarios.edit')->with('id',$id);
}
public function update(Request $request, $id)
{
$user = User::find($id);
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = Input::get('password');
$user->save();
}
public function destroy($id)
{
//
}
}
If someone can give me a hand, I will thank them very much!
Auth::user()->slug
on blade route method? You can simply get it on controller – sta