kendrick's avatar

Upload Avatar: Route [$login] not defined Err

As I wanted to upload a new avatar to my test user profile, I got back this error. I have changed nothing, and it worked before. Now this err comes up from nothing, when pushing the update button.

UploadController.php:

class UploadController extends Controller {

    public function index(){

        return view ('profile.editavatar');
    }

    public function store(Request $request){

        $this->validate($request, [
            'avatar' => 'max:600',

        ]);


        if($request->hasFile('avatar')){

            $user = Auth::user();

            $image   = $request->file('avatar');
            $filename = time() . '.' . $image->getClientOriginalExtension();
            $location = public_path('uploads/avatars/'. $filename);
            Image::make($image)->resize(300,300)->save($location);
            
            
            $user->avatar = $filename;
            $user->save();  
        }

        return view ('profile.editavatar');
        
    }

     public function getAvatar(){
        return $this->avatar;
    }


}

Route:

Route::get('/user/edit', [
    'uses' => '\App\Http\Controllers\UploadController@index', 
    'as' => 'profile.editavatar',
    'middleware' => ['auth'],
    ]);

Route::post('/store',[
    'uses' => '\App\Http\Controllers\UploadController@store', 
    'middleware' => ['auth'],
]);

This is really weird. Maybe I am missing something? On my second system this process works without any problems. Thank you, guys.

0 likes
4 replies
ardnor's avatar
ardnor
Best Answer
Level 6

@splendidkeen do you logged already? Do you have login route or can you show me your all routes?

kendrick's avatar

@lancecoder This is my Sign in Route:

Route::get('/login', [
    'uses' => '\App\Http\Controllers\AuthController@getSignin', 
    'as' => 'auth.signin',
    'name' => 'login',
    'middleware' => ['guest'],
    ]);

Route::post('/login', [
    'uses' => '\App\Http\Controllers\AuthController@postSignin',
    'name' => 'login',
    'middleware' => ['guest'],
    ]);


kendrick's avatar

@RamjithAp After pushing the Upload button it results in the Route [$login] not defined Err.

It is weird, because I can change other content within the same profile from my edit.blade.php view which has its own Controller.

Plus at the beginning it got an Err that it couldn't find the editavatar.blade.php Route, because I mentioned it within a Navigation on the view.

For this particular Route it got an Err:

(div class="col-sm-3")
    (a href="{{route('profile.editavatar')}}")(h4 class="headernav"  style="text-decoration: none;")Pictures & Avatar(/h4)(/a)
(/div)

editavatar.blade.php:


(form) enctype="multipart/form-data" action="/store" method="POST"(/)

    (label id="labeledit2") Update profile image(/label)
            
    (input) type="file" name="avatar"(/)
                
    (div) class="form-group"(/)
    (button type="submit" class="btn btn-default" style="margin-top: 20px; color: white;" id="button-profile")Update(/button)
    (/div)
    (input type="hidden" name="_token" value="{{ Session::token() }}")
        (/form)


Please or to participate in this conversation.