Ad

Method App\Http\Controllers\VerifyController::update Does Not Exist

- 1 answer

I am new at Laravel and of what I am done is create a user and then a link verification sent. I created a VerifyController to do it, that includes the code below:

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers;

    class VerifyController extends Controller
    {
        /**
         * verify the user with a given token
         * 
         * 
         * @param string $token
         * 
         * @return Response
         */
        public function verify($token)
        {
            User::where('token', $token)->firstOrFail();

                $this->update(['token' => null]); //verify the user;


                $this->route('home');
                $this->with('success', 'Account verifed');

        }
    }

So when you get the verification email you press the button so user will be confirmed but at the code does not accept the update. I am wondering if missing a library or something.
I hope i was cleared about my question.
I am using Laravel Framework 7.1.3 and the idea of this project was made of 5.5 version Laravel Framework version.
I tried using update(['token' => null]); //verify the user; without $this but nothing, also ->update(['token' => null]); //verify the user;

Ad

Answer

You should assign queried user to a variable first and then call update on this variable like so;

class VerifyController extends Controller
{
    /**
     * verify the user with a given token
     * 
     * 
     * @param string $token
     * 
     * @return Response
     */
    public function verify($token)
    {
        $user = User::where('token', $token)->firstOrFail();

            $user->update(['token' => null]); //verify the user;


            $this->route('home');
            $this->with('success', 'Account verifed');

    }
}
Ad
source: stackoverflow.com
Ad