Laravel: method BadMethodCallException [find] does not exist

when trying to extract some values ​​from the database using the model object, the user receives the following error: BadMethodCallException Method [find] does not exist

Here are my files: Model user

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

        public function projects()
        {
            return $this->belongsToMany('Project');
        }

        public function trys()
        {
            return $this->hasMany('Try');
        }

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

}

Controller User:

<?php

class user extends BaseController {


    public function showWelcome($id)
    {
        $user1 = User::find($id);
        return View::make('users.index', array('user' => $user1)); //
    }

}

View Users /index.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>first page</title>

</head>
<body>
    <?php echo 'Hello'; ?>
</body>
</html>

and route.php:

<?php
Route::get('user/{id}', 'user@showWelcome');
Route::get('/', function()
{
    return View::make('hello');
});

thanks for the help

+4
source share
2 answers

You should not get this error because it seems like you are using Eloquent and there is a method on it find().

But you get this error, and there are several possible reasons:

1) You are User::not calling the same thing that you are showing here to check execution in the controller:

$reflector = new ReflectionClass("User");
$fn = $reflector->getFileName();
dd($fn);

.

2) - , :

composer dumpautoload

.

3) - Laravel, Laravel:

rm -rf vendor/laravel

composer update
+13

, Laravel , , . " ". : Form db ( ): forms.

cmd FormController:

$reflector = new ReflectionClass("Form");
$fn = $reflector->getFileName();
dd($fn);

, "" < > Illuminate:

"/home/pkanane/laravel_appz/cpay/vendor/laravel/framework/src/Illuminate/Support/Facades/Form.php" 

, WebForm db web_forms

+4

Source: https://habr.com/ru/post/1535162/


All Articles