在 laravel 4 中跨多个表进行全文搜索

Full text search in laravel 4 across multiple tables

我有一个正在进行的项目,需要对数据库中的多个表进行全文搜索。我在这里找到了有用的教程:

http://creative-punch.net/2013/12/implementing-laravel-4-full-text-search

我已经让它在一张桌子上工作,但现在希望扩展到多张桌子。我遇到的问题是;如果重复表的其余部分有什么,当我点击提交时,我如何获得按钮来检查多个控制器?或修改现有控制器以检查多个表?

代码

默认视图表单

<div class="search">
    {{ Form::model(null, array('route' => array('search'))) }}
    {{ Form::text('query', null, array( 'placeholder' => 'Search query...' )) }}
    {{ Form::submit('Search') }}
    {{ Form::close() }} 
</div>

返回视图

<div class="search">
    {{ Form::model(null, array('route' => array('search'))) }}
    {{ Form::text('query', null, array( 'placeholder' => 'Search query...' )) }}
    {{ Form::submit('Search') }}
 @foreach($posts as $post)
    <li>{{ $post->instance_id }}</li>
    <li>{{ $post->instance_type }}</li>
    <li>{{ $post->availability_zone }}</li>
    <li>{{ $post->status_checks }}</li>
    <li>{{ $post->alarm_status }}</li>
    <li>{{ $post->public_dns }}</li>
    <li>{{ $post->key_name }}</li>
 @endforeach
{{ Form::close() }}
</div>

控制器 class

<?php 
class PostsController extends BaseController {

public function postSearch(){
    $q = Input::get('query');

   $posts =     ec2_instance::whereRaw("MATCH(instance_id,instance_type,availability_zone, status_checks,alarm_status, public_dns, key_name ) AGAINST(? IN BOOLEAN MODE)", 
        array($q))->get();
        View::share('posts', $posts);

    return View::make('ec2_instance', compact('posts'));

}
}
?>

我最初的想法是修改控制器,以便添加:

 $ip_address = public_ip::whereRaw("MATCH(ip_address) AGAINST(? IN BOOLEAN      MODE)",     
         array($q))->get();'

然后在视图中添加

     @foreach($ip_address as $ip)
         <li>{{ $ip->ip_address}}</li>
     @endforeach

但是找不到变量 ip_address

我 return 获得了 2 个视图,这是不可能的,按照我最初的想法确保你只有 return 1 个视图,即

$posts = ec2_instance::whereRaw("MATCH(instance_id,instance_type,availability_zone, status_checks,alarm_status, public_dns, key_name ) AGAINST(? IN BOOLEAN MODE)", array($q))->get();



 $ip_address =
 public_ip::whereRaw("MATCH(ip_address ) AGAINST(? IN BOOLEAN MODE)",           array($q))->get();


$s3_bucket = 
 s3_bucket::whereRaw("MATCH(name, storage_class, size ) AGAINST(? IN BOOLEAN MODE)", array($q))->get();

 $cloudfront_distribution =    cloudfront_distribution::whereRaw("MATCH(delivery_method, cloudfront_id, domain_name,comment, origin, c_name, status, state ) AGAINST(? IN BOOLEAN MODE)", array($q))->get();

return View::make('ec2_instance', compact('ip_address', 'posts','s3_bucket', 'cloudfront_distribution'));