【问题标题】:Call to a member function links() on array in Laravel在 Laravel 中调用数组上的成员函数 links()
【发布时间】:2017-07-17 08:10:47
【问题描述】:

我在尝试在 laravel 中创建分页时收到此错误。

1e886a45102a3e4898f23b52cd7ca771 第 396 行中的 ErrorException:调用 数组上的成员函数 links()(查看: C:\xampp\htdocs\soulfy_repo\framework\resources\views\soulfy\setting.blade.php)

line 396:  <?php echo e($themes->links()); ?>

HomeController.php

public function getBackgroundTheme()
{

    $query = DB::table('theme_background');

    if (request()->has('menu')) {
        $theme = DB::table('kategori_name')->where('kategori_theme', request('menu'))->first();

        $query = $query->where('kategori_id', $theme->kategori_id);
    }

    //$model = $query->get();
    $theme = $query->paginate(4);

    return view('soulfy.setting', [
        'themes'=>$theme,
        'user' => auth()->user(),
    ]);


    // return redirect('/home/setting' . 
}

setting.blade.php

        <table>

    @if(isset($themes))
        @foreach($themes as $m)

            <tr>
                <td><img width="100px" height="100px" src="{{url('/')}}/uploads/theme/{{$m->pic_name}}.jpg"/></td>
                <td><img width="100px" height="100px" src="{{url('/')}}/uploads/theme/{{$m->pic_name}}.jpg"/></td>
                <td><img width="100px" height="100px" src="{{url('/')}}/uploads/theme/{{$m->pic_name}}.jpg"/></td>
            </tr>

            <tr>
                <td><div class="box"><input type="checkbox" name="pic" value=""></div></td>
                <td><input type="checkbox" name="pic" value=""></td>
                <td><input type="checkbox" name="pic" value=""></td>
            </tr>

        @endforeach

        {{ $themes->links() }}
    @endif


</table>

【问题讨论】:

  • 尝试评论if 块:这个if (request()-&gt;has('menu')) { $theme = DB::table('kategori_name')-&gt;where('kategori_theme', request('menu'))-&gt;first(); $query = $query-&gt;where('kategori_id', $theme-&gt;kategori_id); } 看看它是否有效
  • 仍然有同样的错误信息

标签: laravel pagination


【解决方案1】:
 $theme = DB::table('kategori_name')->where('kategori_theme', request('menu'))->paginate(PAGELIMIT);

在您的家庭控制器中使用它。而不是 first(); 并在您的路线中定义:define('PAGELIMIT','4');

【讨论】:

    猜你喜欢
    • 2018-12-21
    • 1970-01-01
    • 2021-09-04
    • 2019-01-22
    • 1970-01-01
    • 2022-01-22
    • 2017-05-22
    • 2018-06-28
    • 2017-12-04
    相关资源
    最近更新 更多