Laravel 4如何过滤多态表

时间:2014-04-08 13:55:15

标签: laravel laravel-4

我有一个名为' Item':

的多态表
    Schema::create('items', function(Blueprint $table) {
        $table->increments('id');
        $table->text('itemable_type')->nullable();
        $table->string('itemable_id')->nullable();
        $table->integer('subject_id')->nullable();
        $table->integer('user_id')->nullable();
        $table->integer('new')->nullable();
        $table->integer('school')->nullable();
        $table->string('private')->nullable();
        $table->text('snippet')->nullable();
        $table->string('elementSubject')->nullable();
        $table->integer('follow_id')->nullable();
        $table->timestamps();
    });

还有一个名为' Follow':

的表格
    Schema::create('follows', function(Blueprint $table) {
        $table->increments('id');
        $table->integer('subject_id')->nullable();
        $table->integer('teacher_id')->nullable();
        $table->integer('user_id')->nullable();
        $table->integer('effort')->nullable();
        $table->timestamps();
    });

还有一个名为' Subject':

的表格
    Schema::create('subjects', function(Blueprint $table) {
        $table->increments('id');
        $table->string('name')->nullable();
        $table->integer('studentID')->nullable();
        $table->integer('teacherID')->nullable();
        $table->integer('schoolID')->nullable();
        $table->integer('memberID')->nullable();
        $table->string('private')->nullable();
        $table->integer('creator')->nullable();
        $table->softDeletes();
        $table->timestamps();
    });

它们在我的模型中像这样链接在一起:

    class Follow extends Eloquent {
        protected $guarded = array();

        public static $rules = array();

        public function subjects()
        {
            return $this->hasMany('Subject');
        }

我想过滤'项目'列表基于'主题' '用户'正在关注。我的Eloquent会是什么样子?

我对学校'但我希望根据用户的情况对其进行过滤'关注'

    $follows = Follow::where('user_id', Auth::user()->id)->get();
    $items = Item::where('school', Auth::user()->school)
    ->where('private', 'false')
    ->orderBy('created_at', 'DESC')
    ->get();

0 个答案:

没有答案