0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Laravel】jScrollで無限スクロール

Posted at

jScrollファイルをダウンロード#

 こちらからjScrollをダウンロードして、public/jsディレクトリ内に「jquery.jscroll.min.js」ファイルを入れます。

ファイルの読み込み#

 jScrollを使うには、ファイルを読み込む必要があります。
HTMLのheadにこのように記述します。

view.blade.php
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
     
       //〜略

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="{{ asset('js/jquery.jscroll.min.js') }}" defer></script>

   //〜略
    </head>

asset関数で、publicディレクトリ内のファイルを読み込むことができます。
この時、jQueryも一緒に読み込んでおきます。

controllerの書き方#

コントローラーではモデルで取得したデータを受け取ります。

controller.php
$products = DB::table('products')->paginate(15);

paginate関数の引数には、取得するデータの件数を入れます。今回は15件ずつデータを取得してきます。

viewの書き方#

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?