4

I m using Laravel 5.4 getting the above error

Call to undefined method Illuminate\Database\Query\Builder::notify()

i have came accross this solution

You must add Illuminate\Notifications\Notifiable trait in User model. (link:Call to undefined method Illuminate\Database\Query\Builder::notify())

even though it is not working for me

Below is my User model i haven't created any folder for models its path is default

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{

    use Notifiable;         

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','phone','address','google_id',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];


    public function product()
    {
        return $this->hasMany('App\Product');
    }  
}

during getting above error my current url is
http://localhost:8000/password/email

enter image description here

i have tried many previous versions solution but still does not work?

UPDATE 1: HERE IS MY PROJECT ON DROPBOX https://www.dropbox.com/s/8jr6ls6xo7flbv8/myproject.zip?dl=0

My interest is only password reset http://localhost:8000/password/reset (where i'm getting error)

Please Help Me To Get Rid Of This Error Thanks in Adavce!!!

Please Help Me To Get Rid Of This Error Thanks in Adavce!!!

  • Have you done everything listed in this answer: https://stackoverflow.com/a/40314170/1287695 ? – kjones Jul 08 '17 at 09:08
  • @kjones,yes i have tried those thing mentioned there –  Jul 08 '17 at 10:32
  • i have uploaded my project on `drop box` https://www.dropbox.com/s/8jr6ls6xo7flbv8/myproject.zip?dl=0 please hit this url to test it http://localhost:8000/password/reset –  Jul 08 '17 at 16:16
  • @EaB i have seen your code where you trying to notify a user? – FULL STACK DEV Jul 08 '17 at 16:49
  • @AdnanMumtaz, i'm trying to use the default forgot password functionality which is built-in in laravel. if you have any solution please post –  Jul 09 '17 at 03:14

1 Answers1

1

Why do you have duplicate files ?!

Delete User (2).php and Category (2).php

For some reason, file User (2).php, which does not have the Notify trait is the one loaded. Thus, you got this error.

Just delete the extra files.

Hamoud
  • 1,909
  • 9
  • 13
  • 1
    Great Great !!! it worked for me after Deleting `User(2).php` and `Category(2).php` Then `php artisan cache:clear` and then `composer dump-autoload` –  Jul 10 '17 at 05:47
  • 1
    i struggled a lot to get `answer` for this `question` i have to `edit` `question` every hour to reach more audiences after crossing `101 view` i got the answer thanks alot –  Jul 10 '17 at 05:51
  • 1
    Never thought about that `Laravel` will `look` for `User(2).php` instead `User.php` –  Jul 10 '17 at 05:52
  • 1
    You're welcome. It's composer loading the files not laravel. It's wired to me that this file is matched to the User class when it's does not have the same name. I bet because of the space in the file name, composer treat the file as User.php. Try to be careful about the files you include in your project. It looks like you were trying to keep unmodified copy of the files to refer to. Try to store them outside of your project. Yet better, use Git and be a real developer. Good luck. – Hamoud Jul 10 '17 at 05:57