鍍金池/ 問答/PHP/ laravel用user模型找不到

laravel用user模型找不到

控制器里寫了一個(gè)方法:

  public function edit($id)
    {
        $question = $this->questionRepository->byId($id);

        if (Auth::user()->owns($question)) {
          return view('questions.edit',compact('question'));
        }

        return back();

        //return view('questions.edit', compact('question'));
    }

里面的owns是自己定義的,再user里面:

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

class User extends Authenticatable
{
    use Notifiable;

    public function owns(Model $modle)
    {
        return $this->id == $model->user_id;
    }
}

就會報(bào)錯(cuò):"Type error: Argument 1 passed to AppUser::owns() must be an instance of AppModel, instance of AppQuestion given

clipboard.png

回答
編輯回答
茍活

。。。。owns方法要傳AppModel實(shí)例啊,你傳了AppQuestion實(shí)例

2018年3月28日 07:34