Laravel Controller其中(' like')子句返回额外参数

时间:2017-11-10 01:15:33

标签: laravel backpack-for-laravel

我使用Laravel Backpack的JSON选择过滤器,当它返回结果时,它的添加和额外参数:

public function albumsOptions() {
    $term = $this->request->input('term');
    $options = AlbumsModel::where('title', 'like', "%".$term."%")->get();
    return $options->pluck('title');
}

它返回的参数是:

title:0 
title_text:Grey 2012 Cadillac CTS

但他们预期并且需要:

title:Grey 2012 Cadillac CTS

不确定获取title_text参数的位置或者为什么将标题传递给title而不是'like'

似乎它与where子句中的'='语句有关,因为我有另一个使用 <!-- Your site title as branding in the menu --> <div class="container"> <div class="row"> <div class="col-md-6"> <?php if ( ! has_custom_logo() ) { ?> <?php if ( is_front_page() && is_home() ) : ?> <h1 class="navbar-brand mb-0"><a rel="home" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1> <?php else : ?> <a class="navbar-brand" rel="home" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><?php bloginfo( 'name' ); ?></a> <?php endif; ?> <?php } else { the_custom_logo(); } ?> </div> </div> <!-- end custom logo --> <div class="row"> <div class="col-md-6"> <p class="text-right">Call Now</br> <a href="tel:636-244-4444">636-244-4444</a></p> </div> </div> </div> 的过滤器,它可以正常工作。

1 个答案:

答案 0 :(得分:1)

我的错误出现在categoryOptions函数

public function albumsOptions() {
    $term = $this->request->input('term');
    $options = AlbumsModel::where('title', 'like', "%".$term."%")->get();
    return $options->pluck('name');
}

我的pluck()参数错误