2015-07-11 127 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

相關問題