gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:32:54 25 4
gpt4 key购买 nike

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

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

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

代码

默认 View 表单

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

返回 View

<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>

Controller 类

<?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'));

}
}
?>

我最初的想法是修改 Controller ,这样你就可以添加:

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

然后在 View 中添加

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

但是找不到变量 ip_address

最佳答案

我返回了 2 个 View ,这是不可能的,按照我最初的想法确保您只返回 1 个 View ,即

$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'));

关于php - 在 laravel 4 中跨多个表进行全文搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27739765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com