Call to undefined method error

Joe

Get the following error. Not sure how to fix it. I may have things in the wrong areas as this is my first laravel project so I am not sure if I am doing it correctly.

BadMethodCallException in Builder.php line 1994:
Call to undefined method Illuminate\Database\Query\Builder::getLewpByName()

Contents of EloquentLewpRepository

<?php namespace App\Repositories\Frontend\Lewp;

use App\Lewp;   
use App\Exceptions\GeneralException;

/**
 * Class EloquentUserRepository
 * @package App\Repositories\Lewp
 */
class EloquentLewpRepository implements LewpContract {



    /**
     * @param $id
     * @return \Illuminate\Support\Collection|null|static
     * @throws GeneralException
     */
    public function findOrThrowException($id) {
        $lewp = Lewp::find($id);
        if (! is_null($lewp)) return $lewp;
        throw new GeneralException('That lewp does not exist.');
    }

    /**
     * @param $data
     * @param bool $provider
     * @return static
     */

    public function create($data) {
        $lewp = Lewp::create([
            'name' => $data['name'],
            'title' => $data['title'],
            'text' => $data['text'],
            'sidebar' => $data['sidebar'],
            'submission_text' => $data['submission_text'],
            'type' => $data['type'],
            'content_options' => $data['content_options'],
            'link_button_text' => $data['link_button_text'],
            'text_button_text' => $data['text_button_text'],
            'options' => $data['options'],
            'comment_sort_method' => $data['comment_sort_method'],
            'hide_comment_scores' => $data['hide_comment_scores'],
            'header_mouseover-text' => $data['header_mouseover-text']
        ]);

        return $lewp;
    }

    public function searchLewpsByName($term) {
        $lewp = Lewp::where('name', 'LIKE', $term)->get();

        return $lewp;
    }

    public function getLewpByName($lewpname) {
        $lewp = Lewp::where('name', '=', $lewpname)->first();

        return $lewp;
    }

    public function getLewpId($lewpname) {
        $lewp = Lewp::select(array('id')->where('name', '=', $lewpname)->first();

        return $lewp;
    }

}

Contants of App/Lewp

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Lewp extends Model
{
    use SoftDeletes;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'lewps';

    /**
     * The attributes that are not mass assignable.
     *
     * @var array
     */
    protected $guarded = ['id'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [];

    /**
     * For soft deletes
     *
     * @var array
     */
    protected $dates = ['deleted_at'];   
}

Contents of Controller

<?php namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Lewp;

/**
 * Class FrontendController
 * @package App\Http\Controllers
 */
class FrontendController extends Controller {

    /**
     * @return \Illuminate\View\View
     */
    public function index()
    {
        return view('frontend.index');
    }

    /**
     * @return \Illuminate\View\View
     */
    public function macros()
    {
        return view('frontend.macros');
    }
    public function post()
    {
        return view('frontend.post');
    }
    public function exterior()
    {
        return view('frontend.exterior');
    }
    public function submit()
    {
        return view('frontend.submit');
    }
    public function self()
    {
        return view('frontend.self');
    }
    public function lewp($name)
    {
        if(strlen($name) == 0)
        {
            return view('frontend.index');
        }
        $lewp = Lewp::getLewpByName($name);
        return view::make('frontend.lewp', array('lewp' => $lewp));
    }
}
ThinhBuzz

You create method getLewpByName in class EloquentLewpRepository, but in FrontendController you call Lewp::getLewpByName with Lew is model. Do you understand problem? With this approach you should learn more about the IOC on documents.

P/s: excuse me my English.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error: Call to a possibly undefined method

From Dev

Call to undefined method error in Laravel

From Dev

Method call throws an "undefined method" error

From Dev

PHP Error: Fatal error: Call to undefined method

From Dev

CakePHP error: Call to undefined method FlashComponent::error()

From Dev

"Cannot call method 'transaction' of undefined" error in indexedDB

From Dev

Karma error Cannot call method 'module' of undefined

From Dev

Fatal error: Call to undefined method PDOStatement::lastInsertId()

From Dev

PHPUnit fatal error call to undefined method on mock

From Dev

Fatal error: Call to undefined method Database::prepare()

From Dev

DataTransformer get error "undefined call method getName"

From Dev

Fatal error: Call to undefined method getLoginStatusUrl

From Dev

Fatal error: Call to undefined method DOMDocument::getElementsById()

From Dev

Fatal Error :: Call to undefined method in codeigniter

From Dev

Fatal error: Call to undefined method DB::getInstance()

From Dev

Fatal error Call to undefined method VmVendorPDF::convertHTMLColorToDec()

From Dev

PHP Classes - Fatal error: Call to undefined method

From Dev

PHP: Fatal error: Call to undefined method mysqli

From Dev

Fatal error: Call to undefined method DOMDocument::getElementsById()

From Dev

CakePHP call to undefined method stdClass::read() error

From Dev

xampp - Fatal error: Call to undefined method

From Dev

Fatal error: Call to undefined method db::_results()

From Dev

Fatal error: Call to undefined method PDOStatement::lastInsertId()

From Dev

Fatal error: Call to undefined method MongoCollection::insertMany()?

From Dev

Fatal error: Call to undefined method connectDB::prepare()

From Dev

JQueryValidation plugin error: "Uncaught TypeError: Cannot call method 'call' of undefined"

From Dev

PHP - Fatal Error: Call to undefined method - but method exist

From Dev

Fatal error: Call to undefined method JToolbarHelper::deleteListX() in joomla

From Dev

How to catch the "Call to undefined method" error in PHP 7?

Related Related

  1. 1

    Error: Call to a possibly undefined method

  2. 2

    Call to undefined method error in Laravel

  3. 3

    Method call throws an "undefined method" error

  4. 4

    PHP Error: Fatal error: Call to undefined method

  5. 5

    CakePHP error: Call to undefined method FlashComponent::error()

  6. 6

    "Cannot call method 'transaction' of undefined" error in indexedDB

  7. 7

    Karma error Cannot call method 'module' of undefined

  8. 8

    Fatal error: Call to undefined method PDOStatement::lastInsertId()

  9. 9

    PHPUnit fatal error call to undefined method on mock

  10. 10

    Fatal error: Call to undefined method Database::prepare()

  11. 11

    DataTransformer get error "undefined call method getName"

  12. 12

    Fatal error: Call to undefined method getLoginStatusUrl

  13. 13

    Fatal error: Call to undefined method DOMDocument::getElementsById()

  14. 14

    Fatal Error :: Call to undefined method in codeigniter

  15. 15

    Fatal error: Call to undefined method DB::getInstance()

  16. 16

    Fatal error Call to undefined method VmVendorPDF::convertHTMLColorToDec()

  17. 17

    PHP Classes - Fatal error: Call to undefined method

  18. 18

    PHP: Fatal error: Call to undefined method mysqli

  19. 19

    Fatal error: Call to undefined method DOMDocument::getElementsById()

  20. 20

    CakePHP call to undefined method stdClass::read() error

  21. 21

    xampp - Fatal error: Call to undefined method

  22. 22

    Fatal error: Call to undefined method db::_results()

  23. 23

    Fatal error: Call to undefined method PDOStatement::lastInsertId()

  24. 24

    Fatal error: Call to undefined method MongoCollection::insertMany()?

  25. 25

    Fatal error: Call to undefined method connectDB::prepare()

  26. 26

    JQueryValidation plugin error: "Uncaught TypeError: Cannot call method 'call' of undefined"

  27. 27

    PHP - Fatal Error: Call to undefined method - but method exist

  28. 28

    Fatal error: Call to undefined method JToolbarHelper::deleteListX() in joomla

  29. 29

    How to catch the "Call to undefined method" error in PHP 7?

HotTag

Archive