Php 如何排除laravel中的某些特定对象

Php 如何排除laravel中的某些特定对象,php,laravel,laravel-4,laravel-3,Php,Laravel,Laravel 4,Laravel 3,我的Laravel应用程序中有两个表。第一个是集合,第二个是q_集合。集合表包含一些对象。q_collections对集合有多对一字段,这意味着q_collections表的集合对象id为c_id。我想从集合表中排除与q_集合相关的对象。两个表中都有一个字段sd\u item\u id。我想使用此sd\u item\u id筛选表,以获得唯一记录或那些在q\u集合中不可用的记录 桌子就像 //Collection class CreateCollection extends Migration

我的Laravel应用程序中有两个表。第一个是集合,第二个是q_集合。集合表包含一些对象。q_collections对集合有多对一字段,这意味着q_collections表的集合对象id为c_id。我想从集合表中排除与q_集合相关的对象。两个表中都有一个字段
sd\u item\u id
。我想使用此
sd\u item\u id
筛选表,以获得唯一记录或那些在q\u集合中不可用的记录

桌子就像

//Collection
class CreateCollection extends Migration {
public function up()
{
    Schema::create('collection', function (Blueprint $table) {
        $table->increments('id')->unsigned();
        $table->string('name');
        $table->timestamps();

    });
}

public function down()
{
    Schema::drop('collection');

}
}
//q_collections
class CreateQCollections extends Migration {
public function up()
{
    Schema::create('q_collections', function(Blueprint $table) {
    $table->increments('id');
    $table->integer('sd_item_id')->unsigned();
            $table->integer('qc_id')->unsigned();     // question collection id 
            $table->timestamps();
    $table->foreign('qc_id')->references('id')->on('collection');
    });
}

public function down()
{
    Schema::drop('q_collection');
}
}

您可以为此使用Laravel查询生成器

$collection_count=DB::table('q_collections')->where('sd_item_id','=',$item_id)->count();  
if($collection_count){  
    $sc=DB::table('q_collections')->where('sd_item_id','=',$item_id)->lists('qc_id');
}
else{
    $sc=array(0);
}
$collections=DB::table('collection')->whereNotIn('id',$sc)->get();
return Response::json($collections);
可能还有其他一些方法来执行此任务。
我对laravel也是新手,所以我也说这个代码是否完美,但它肯定会工作

你能再解释一下吗?我不清楚您想要什么。表与表B有一对多关系。我想获取表A中与表B无关的项目。例如,我有两个表,问题和答案具有一对多关系。问题表有10个问题,但答案表中只有5个问题的答案。我想把答案不在答案表中的5个问题拿出来。