dimanche 29 avril 2018

"No message" error laravel - trying to update user account information

I'm receiving the error "MethodNotAllowedHttpException No message" on submit of my user's form, which is meant to update the user's table. I have two post forms on the same page and two post routes, would that have something to do with it?

I will include all the routes and another form that might be conflicting with it.

web.php

Route::get('profile','userController@profile');
Route::post('profile', 'userController@update_avatar');
Route::post('profile-update', 'userController@update_account'); //this ones not working

userController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

use Auth;

use Image;

class UserController extends Controller
{
    //
    public function profile()
    {
        return view('profile', array('user' => Auth::user()) );
    }

    public function update_avatar(Request $request)
    {
        if($request->hasFile('avatar')){
            $avatar = $request->file('avatar');
            $filename = time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->resize(300,300)->save( public_path('/uploads/avatars/' . $filename) );

            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();

        }
        return view('profile', array('user' => Auth::user()) );
    }

    public function update_account(Request $request, $id) //the function with the error
    {

         User::update([ 
                'id' => Auth::user()->id,
                'name' => $request->name,
                'email' => $request->email
            ]);
            return redirect('/profile');

    }
}

profile.blade.php

 <img src="/uploads/avatars/" style="width:150px;height:150px;float:left;border-radius:50%;margin-right:25px">    
                <h2>'s Profile</h2>

                <form enctype="multipart/form-data" action="/profile" method="post">
                    <label>Update Profile Image</label>
                    <input type="file" name="avatar">
                    <input type="hidden" name="_token" value="">

                    <input type="submit" class=" btn btn-sm btn-light" style="color:#2b2b2b;" value="Update Image">
                </form>

                <form method="post" action="/profile-update"> <!-- The form with the error -->
                    
                    
                    <input type="hidden" name="_method" value="PUT" />
                    <label>Username</label>
                    <input type="text" name="name" class="form-control" value="">
                    <label>Email</label>
                    <input type="email" name="email" class="form-control" value="">
                    <input type="submit" id="update-account" class="btn btn-success" value="Update">

                </form>



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2r9xdwq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire