2015-07-11 126 views
0

获取以下错误。不知道如何解决它。我可能在错误的地方有东西,因为这是我的第一个laravel项目,所以我不确定我是否正确地做了这件事。调用未定义的方法错误

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

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; 
    } 

} 

应用/ Lewp的Contants

<?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']; 
} 

控制器

<?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)); 
    } 
} 
+0

那么,如果你使用的存储库模式,你为什么要尝试在模型上调用'getLewpByName()'? – lukasgeiter

+0

@lukasgeiter我不喜欢我在做什么(我是新的存储库模式)。我知道我需要调用getLewpByName,但不知道我是怎么称呼它的。 – Joe

回答

0

您在类中创建方法getLewpByName内容,但在FrontendController中,您可以拨打Lewp::getLewpByName与Lew是模型。你明白问题吗?通过这种方法,您应该了解更多关于国际奥委会的documents

P/s:对不起,我的英语。

+0

我不是很积极你在说什么(我明白我应该使用模型,但不知道我怎么称呼它)。你能解释我怎么称呼它吗?我对这种方法很陌生,所以对它的工作原理并不积极。 – Joe

相关问题