Saturday, April 15, 2017

How do I integreate spf.js and Laravel

I'm trying to build an ajax page navigation using Youtube SPF.js

I didn't find any article about integrating spf.js with Laravel.

Here is my structure :

views/users-list/head.blade.php
views/users-list/body.blade.php
views/users-list/foot.blade.php
views/users-list/index.blade.php

With these contents :

head.blade.php

<link href="/assets/css/style1.css" rel="stylesheet" />
<link href="/assets/css/style2.css" rel="stylesheet" />

body.blade.php

<div class="row">
  <div class="col-md-12">
    <table id="UsersTable" class="table">
      <thead>
      <tr>
          <th>ID</th>
          <th>Last Name</th>
          <th>Email</th>
          <th>Mobile</th>
      </tr>
      </thead>
      <tbody>
        @foreach($users as $user)
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        @endforeach
      </tbody>
  </table>
  </div>
</div>

foot.blade.php

<script src="/assets/global/plugins/bootbox/bootbox.min.js"></script>
<script src="/assets/global/plugins/datatables/datatables.min.js"></script>
<script src="/assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.js"></script>

index.blade.php

{
  "head": "@include('users-list.head')",
  "body": {
    "spf-posts-container": "@include('users-list.body')"
  },
  "foot": "@include('users-list.foot')"
}

And I put a <div id="spf-posts-container"></div> inside of my master page.

And then here is the action in UserController :

public function showUsersList()
{
   $users = User::all();
   return view('users-list.index', compact('users'));
}

I did not succeed so far. Please tell me if you know what am I missing here.

P.S:

Of course I put spf.js file in before end body tag inside master page :

<script src="https://oss.maxcdn.com/spf/2.4.0/spf.js"></script>
<script>
  spf.init();
</script>



via Hamed Kamrava

Advertisement