小编use*_*810的帖子

Laravel Scout:仅搜索特定领域

Laravel Scout:有没有一种方法可以只搜索特定的字段?

目前这条线工作正常:

    $es = Element::search($q)->get();
Run Code Online (Sandbox Code Playgroud)

但它搜索标题,描述描述字段.我需要它只搜索标题字段.

laravel-scout

5
推荐指数
1
解决办法
2405
查看次数

jquery:未捕获TypeError:$(...).错误不是函数

我在我的页面上使用jquery,并没有其他部分的问题.即使$ .post和$ .get也能正常工作.

现在我正在尝试评估图像是否有任何问题并尝试此代码:

$("#bib").error(function(){
   //nothing now 
});
Run Code Online (Sandbox Code Playgroud)

我想知道为什么我得到这个错误:

Uncaught TypeError: $(...).error is not a function
at app.js:53
(anonymous) @ app.js:53
Run Code Online (Sandbox Code Playgroud)

如你所见,我缩短了代码以隔离问题,但你得到了全部的想法.目前,这些jquery源包含在页面内:

https://code.jquery.com/jquery-3.1.0.min.js https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js

知道为什么会这样吗?

jquery

4
推荐指数
1
解决办法
2万
查看次数

如何在Laravel中的get()之后对集合进行分页?

我对两个运行良好的查询结果进行了合并:

$events1 = \App\Event::Where('valid_to','>=',$today)->orderByRaw('valid_to','ASC')->get();
$events2 = \App\Event::Where('valid_to','<',$today)>orderByRaw('valid_to','ASC')->get();
$events = $events1->merge($events2); 
Run Code Online (Sandbox Code Playgroud)

现在,我需要对这个新集合进行分页,并根据建议添加以下内容:

$page = 1;
$perPage = 60;
$pagination = new \Illuminate\Pagination\LengthAwarePaginator(
    $events->forPage($page, $perPage), 
    $events->count(), 
    $perPage, 
    $page
);
Run Code Online (Sandbox Code Playgroud)

编辑:对于未来的读者,爱国者的答案很棒,而我做到了。

paginate laravel

2
推荐指数
2
解决办法
3309
查看次数

从控制台调用 laravel artisan 命令

我正在尝试自学 Laravel 命令,以便稍后我使用它来安排它们。这是我的内核文件:

    namespace App\Console;

    use Illuminate\Console\Scheduling\Schedule;
    use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

    class Kernel extends ConsoleKernel
    {
        /**
         * The Artisan commands provided by your application.
         *
         * @var array
         */
        protected $commands = [
            //
            'App\Console\Commands\FooCommand',      
        ];

        /**
         * Define the application's command schedule.
         *
         * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
         * @return void
         */
        protected function schedule(Schedule $schedule)
        {
            // $schedule->command('inspire')
            //          ->hourly();
            $schedule->command('App\Console\Commands\FooCommand')->hourly();
        }

        /**
         * Register the Closure based commands for the application.
         *
         * @return void
         */
        protected …
Run Code Online (Sandbox Code Playgroud)

command laravel laravel-artisan

1
推荐指数
1
解决办法
9439
查看次数

获取 Woocommerce 中特定产品类别的特定产品属性值

我已经设法使用此代码获取所有颜色属性:

$color_terms = get_terms(
        array(
        'taxonmy'=>'pa_color'
    ));
Run Code Online (Sandbox Code Playgroud)

这适用于商店页面并返回所有颜色,但如何将其限制为特定类别?假设在名为“衬衫”的类别中我只有 2 种颜色,并且我只想显示这 2 种颜色。

php wordpress product custom-taxonomy woocommerce

1
推荐指数
1
解决办法
2471
查看次数