i try to mount a component in a component vue - laravel

i i try to mount a component in a component, this component its a partial, in especifict its a paginator, which i need to integrate, i use props in the paginate component.
but i have a problem, in the console appears the next messagge "Failed to mount component: template or render function not defined." i am new in vue js, i using router-view i don´t know if this
it is affecting en the problem the code its the next :
Pedido.vue
<template>
<div id="pedido" style="margin-top:50px">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Pedidos</h4>
<div class="card-tools" style="position: absolute;right: 1rem;top: .5rem;">
<button type="button" class="btn btn-info" >
Nuevo
<i class="fas fa-plus"></i>
</button>
<button type="button" class="btn btn-primary" >
Recargar
<i class="fas fa-sync"></i>
</button>
</div>
</div>
<div class="card-body">
<div class="mb-3">
<div class="row">
<div class="col-md-2">
<strong>Buscar por :</strong>
</div>
<div class="col-md-3">
<select class="form-control" id="fileds">
<option value="total">Codigo</option>
<option value="name">Nombre</option>
<option value="email">Apellido</option>
<option value="phone">Telefono</option>
<option value="address">Direccion</option>
</select>
</div>
<div class="col-md-7">
<input type="text" class="form-control" placeholder="Buscar">
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th scope="col">Codigo</th>
<th scope="col">Nombre</th>
<th scope="col">Apellido</th>
<th scope="col">Telefono</th>
<th scope="col">Rut</th>
<th scope="col" class="text-center">Action</th>
</tr>
</thead>
<tbody>
<tr v-for="(pedido, index) in pedidos" :key="pedido.codigo">
<th scope="row">{{ index + 1}}</th>
<td>{{ pedido.nombre_cliente}}</td>
<td>{{ pedido.apellido_cliente }}</td>
<td>{{ pedido.telefono_cliente}}</td>
<td>{{ pedido.rut_cliente }}</td>
<td class="text-center">
<button type="button" class="btn btn-info btn-sm">
<i class="fas fa-eye"></i>
</button>
<button type="button" class="btn btn-primary btn-sm">
<i class="fas fa-edit"></i>
</button>
<button
type="button"
class="btn btn-danger btn-sm"
>
<i class="fas fa-trash-alt"></i>
</button>
</td>
</tr>
<tr >
<td colspan="6">
<div class="alert alert-danger" role="alert">No se ah encontrado resultados :(</div>
</td>
</tr>
</tbody>
</table>
<div class="card-footer">
<pagination
v-if="pagination.last_page > 1"
:pagination="pagination"
:offset="5"
#paginate="getData()"
></pagination>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return{
pedidos:[],
pagination: {
current_page: 1,
},
}
},
mounted() {
console.log('Component mounted.')
this.getData();
},
methods:{
getData(){
this.$Progress.start();
axios.get("api/pedidos?page=" + this.pagination.current_page)
.then(response =>{
this.pedidos = response.data.data;
this.pagination = response.data.meta;
this.$Progress.finish();
})
.catch(e =>{
console.log(e)
this.$Progress.fail();
})
//.then(({ data }) => (this.pedidos = data));
}
},
}
</script>
this its PaginationComponent.vue:
<template>
<nav aria-label="...">
<ul class="pagination justify-content-center">
<li class="page-item" :class="{ disabled: pagination.current_page <= 1 }">
<a class="page-link" #click.prevent="changePage(1)" >First page</a>
</li>
<li class="page-item" :class="{ disabled: pagination.current_page <= 1 }">
<a class="page-link" #click.prevent="changePage(pagination.current_page - 1)">Previous</a>
</li>
<li class="page-item" v-for="page in pages" :key="page" :class="isCurrentPage(page) ? 'active' : ''">
<a class="page-link" #click.prevent="changePage(page)">{{ page }}
<span v-if="isCurrentPage(page)" class="sr-only">(current)</span>
</a>
</li>
<li class="page-item" :class="{ disabled: pagination.current_page >= pagination.last_page }">
<a class="page-link" #click.prevent="changePage(pagination.current_page + 1)">Next</a>
</li>
<li class="page-item" :class="{ disabled: pagination.current_page >= pagination.last_page }">
<a class="page-link" #click.prevent="changePage(pagination.last_page)">Last page</a>
</li>
</ul>
</nav>
</template>
<script>
export default {
props:['pagination', 'offset'],
methods: {
isCurrentPage(page){
return this.pagination.current_page === page
},
changePage(page) {
if (page > this.pagination.last_page) {
page = this.pagination.last_page;
}
this.pagination.current_page = page;
this.$emit('paginate');
}
},
computed: {
pages() {
let pages = []
let from = this.pagination.current_page - Math.floor(this.offset / 2)
if (from < 1) {
from = 1
}
let to = from + this.offset -1
if (to > this.pagination.last_page) {
to = this.pagination.last_page
}
while (from <= to) {
pages.push(from)
from++
}
return pages
}
}
}
</script>
app.js
Vue.component('pagination', require('./components/partial/PaginationComponent.vue'));
const app = new Vue({
el: '#app',
router
});
this its the error
but in the extension of vue in the console i see the
properties of the object, this is fine,
but I do not know what I'm doing wrong, like I said I'm new to this.
extension of vue
I hope they understand me,
I would greatly appreciate your help.

Pedido.vue
export default {
components: { pagination },
data(){ ....
maybe is this problem

On the file app.js you apart from especify where you are mounting your component (in this case on the div with id "app"), you also need to tell Vue what to render.
Your component on the app.js file should include a template or a render function, that's why you are getting the error "Failed to mount component: template or render function not defined.
You can add it like this:
const app = new Vue({
el: '#app',
router,
template: '<pagination/>'
});
Or using the render function like this:
import Pagination from './components/partial/PaginationComponent.vue'
const app = new Vue({
el: '#app',
router,
render: (h) => h(Pagination)
});

well, i tried with their answer, but dont worked ,
I managed to solve it by adding:
Vue.component('pagination', require('./components/partial/PaginationComponent.vue').default);

Related

Failed to load excel\laravel-excel

I want to export only filtered data in view blade. I am using Laravel 7 and maatwebsite/excel 3.1 and PHP 7.4.2.
I went through the documentation and applied this:
View
<a href="{!! route('users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
web.php
Route::get('/users/export-filter', 'Admin\UserController#filter')->name('users.export-filter');
UserController.php
public function filter()
{
return Excel::download(new FilterUserExport, 'filter.xlsx');
}
FilterUserExport.php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use Modules\User\Entities\User;
use Illuminate\Contracts\View\View;
class FilterUserExport implements FromView, ShouldAutoSize, WithEvents
{
/**
* #return View
*/
public function view(): View
{
$users = app(User::class)->newQuery();
if ( request()->has('search') && !empty(request()->get('search')) ) {
$search = request()->query('search');
$users->where(function ($query) use($search) {
$query->where('first_name', 'LIKE', "%{$search}%")
->orWhere('last_name', 'LIKE', "%{$search}%")
->orWhere('email', 'LIKE', "%{$search}%")
->orWhere('mobile', 'LIKE', "%{$search}%");
});
}
return view('users.index', compact('users'));
}
/**
* #return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
},
];
}
}
index.blade.php
#extends("admin-panel.layouts.master")
#section("content")
<div class="content-body">
<section class="grid-with-inline-row-label" id="grid-with-inline-row-label">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">
<a data-action="collapse">
<i class="ft-plus mr-1"></i>
ثبت فیلتر
</a>
</h4>
<a class="heading-elements-toggle"><i class="ft-align-justify font-medium-3"></i></a>
<div class="heading-elements">
<ul class="list-inline mb-0">
<li><a data-action="collapse"><i class="ft-plus"></i></a></li>
<li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
<li><a data-action="close"><i class="ft-x"></i></a></li>
</ul>
</div>
</div>
<div class="card-content collapse #if( $errors->any() ) show #endif">
<div class="card-body">
<form action="{!! route('admin::users.index') !!}" method="get">
<div class="form-body">
<div class="row">
<div class="col-6 form-group">
<label for="search">جستجو</label>
<input type="text" name="search" id="search" class="form-control"
placeholder="جستجو..."
aria-label="جستجو" value="{{ request()->query('search') }}">
</div>
<div class="col-6 form-group">
<label for="user_type">گروه کاربری</label>
<select id="user_type" name="user_type" class="form-control">
<option value="" {{ (request()->query('user_type') == '')? "selected" : "" }}>-</option>
<option value="is_special" {{ (request()->query('user_type') == 'is_special')? "selected" : "" }}>کاربر ویژه</option>
<option value="is_user" {{ (request()->query('user_type') == 'is_user')? "selected" : "" }}>کاربر عادی</option>
<option value="is_admin" {{ (request()->query('user_type') == 'is_admin')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-6 form-group">
<label for="target">فیلتر کاربران</label>
<select id="target" name="target" class="form-control">
<option value="" {{ (request()->query('target') == '')? "selected" : "" }}>-</option>
<option value="active" {{ (request()->query('target') == 'active')? "selected" : "" }}>کاربر ویژه</option>
<option value="orderedAtLeastOnce" {{ (request()->query('target') == 'orderedAtLeastOnce')? "selected" : "" }}>کاربر عادی</option>
<option value="orderedInLastMonth" {{ (request()->query('target') == 'orderedInLastMonth')? "selected" : "" }}>مدیریت سیستم</option>
<option value="neverOrdered" {{ (request()->query('target') == 'neverOrdered')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-md-6 form-group">
<label for="categoryId">دسته بندی</label>
{!! Form::select('categoryId', \Modules\Category\Entities\Category::whereNull('parentId')->get()->pluck('title', 'id')->toArray(), null, [
'class' => 'form-control',
'id' => 'categoryId',
'placeholder' => 'انتخاب دسته بندی',
]) !!}
</div>
</div>
<div class="d-flex justify-content-between form-actions pb-0">
<div>
<button type="submit" class="btn btn-primary">ارسال <i class="ft-send position-right"></i>
</button>
<button type="reset" class="btn btn-warning">ریست <i class="ft-refresh-cw position-right"></i>
</button>
</div>
<div>
<a href="{!! route('admin::users.export-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صادر
</a>
<a href="{!! route('admin::users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
<a href="{!! route('admin::users.export-special-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صدور کاربران ویژه
</a>
<a href="{!! route('admin::users.import-excel') !!}" class="btn btn-primary">
<i class="la la-cloud-download"></i>
آپلود
</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div id="recent-transactions" class="col-xl-12 col-12">
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md">
<div class="row justify-content-between align-items-center mr-md-1 mb-1">
<div class="col-sm">
<h4 class="card-title mb-2 mb-sm-0">فهرست کاربران</h4>
</div>
</div>
</div>
<div class="col-auto">
<a href="{!! route('admin::users.create') !!}" class="btn btn-info">
<i class="la la-plus"></i>
ایجاد کاربر جدید
</a>
</div>
</div>
</div>
<div class="card-content">
#if( $users->count() > 0 )
#includeWhen( Module::find('notification') && request()->has('search'), 'user::admin.users._notification' )
<div class="table-responsive">
<table id="recent-orders" class="table table-hover table-xl mb-0">
<thead>
<tr>
<th class="border-top-0"># شناسه</th>
<th class="border-top-0">نام و نام خانوادگی</th>
<th class="border-top-0">موبایل</th>
{{-- <th class="border-top-0">ایمیل</th>--}}
<th class="border-top-0">کد ملی</th>
<th class="border-top-0">مدیر</th>
<th class="border-top-0">وضعیت</th>
<th class="border-top-0">ویژه</th>
<th class="border-top-0">آخرین ورود</th>
<th class="border-top-0">عملیات</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td class="text-truncate">
<i class="la la-dot-circle-o success font-medium-1 mr-1"></i>
{{ $user->id }}
</td>
<td class="text-wrap">
{{ $user->first_name.' '.$user->last_name }}
</td>
<td class="text-wrap">
{{ $user->mobile }}
</td>
{{--<td class="text-wrap">
{{ $user->email }}
</td>--}}
<td class="text-wrap">
{{ $user->national_id }}
</td>
<td class="text-wrap">
#if( $user->is_admin )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( !$user->disabled_at )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->is_special_user == 1 )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->last_login_at )
{{ getShamsiDate($user->last_login_at) }}
#else
—
#endif
</td>
<td>
<div class="row flex-nowrap">
<a href="{{ route('admin::users.show', $user) }}" class="mr-1">
<i class="ft-eye text-grey text-shadow-custom font-medium-5 font-weight-normal"></i>
</a>
<a href="{{ route('admin::users.edit', $user) }}" class="mr-1">
<i class="ft-edit text-grey text-shadow-custom font-medium-4 font-weight-normal"></i>
</a>
<form action="{{ route('admin::users.destroy', $user) }}"
method="post"
#submit.prevent="confirmDelete">
#method('delete')
#csrf
<button type="submit" class="btn btn-default p-0">
<i class="ft-trash-2 text-grey font-medium-5 font-weight-normal"></i>
</button>
</form>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pagination-flat">
{{ $users->links() }}
</div>
</div>
#else
<div class="text-center my-2">
<p>نتیجه‌ای برای نمایش وجود ندارد.</p>
</div>
#endif
</div>
</div>
</div>
</div>
</section>
</div>
#endsection
I get this error
The export submit button is sending everything to Excel. How do I make it to send only the filtered data. Thanks
You need to get rid of the other HTML in your view such as forms, inputs, and buttons. Keep the view only to a minimum of the table that needed for your Excel.

I want to set local-storage and qty increment in every click when product ID already exist in cart by Vue.js

I made a shopping cart, where a product item gets added to the cart. When I click the product, it gets stored in a cart, but not local storage. I set it local-storage. When I click a product that already exists in the cart, I want to increment its quantity, but that's not happening. It adds another row instead, which I want to prevent.
Here is my component:
<template>
<div class="row">
<div class="col-md-8">
<div v-for="(product, id) in products" :key="id" class="col-xl-3 col-sm-6 mb-3 float-left">
<div class="card o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-comments"></i>
</div>
<div class="mr-5">{{product.name}}</div>
</div>
<div class="card-footer clearfix small z-1 form-group row" href="#">
<span class="float-left"><input type="text" v-model="product.qty" class="form-control form-control-sm mb-2"></span>
<strong class="float-right col-sm-6">
{{product.price}} TK
</strong>
<button class="btn btn-sm btn-info float-right col-sm-6" #click="addToCart(product)">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<table class="table table-sm">
<thead>
<tr>
<th>#SL</th>
<th>Name</th>
<th>Qty</th>
<th>Price</th>
<th>L/T</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr v-for="(cart, i) in carts" :key="i">
<td>{{cart.id}}</td>
<td>{{cart.name}} </td>
<td class="text-right">{{cart.qty}}</td>
<td class="text-right">{{cart.price}}</td>
<td class="text-right">{{cart.price*cart.qty}}</td>
<td><button type="button" #click="removeProduct(i)" class="btn btn-sm btn-danger">x</button></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4" class="text-right font-weight-bold">Total</td>
<td class="text-right"> {{total}}/-</td>
</tr>
</tfoot>
</table>
<div>
<button class="btn btn-sm btn-info float-right">Checkout</button>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
products:[],
carts:[],
}
},
computed:{
total(){
var total = 0
this.carts.forEach(cart => {
total += parseFloat(cart.price * cart.qty)
})
return total
},
},
mounted(){
this.showProduct()
},
methods:{
showProduct(){
axios.get('api/pos')
.then(res=>{
this.products = res.data.data
});
},
addToCart(product){
this.carts.push(product)
},
removeProduct(i){
this.carts.splice(i,1)
}
}
}
</script>
Here is the screenshot:
The problem is addToCart() just pushes another product into the cart without checking if it already exists.
To fix the problem, update that method to find the item, and increment the item's quantity if found. Otherwise, push another item into the cart:
addToCart(product) {
if (this.carts.find(p => p.id === product.id)) {
product.qty++
} else {
this.carts.push(product)
}
}

Info not displaying in modal, however no errors and Vue component works in console

Looking to display data in a modal. My set up is as follows:
app.js
Vue.component('modal', require('./components/Modal.vue'));
const app = new Vue({
el: '#vue',
data() {
return {
id: '',
booking_start: '',
booking_end: '',
car: [],
user: []
};
},
});
Modal.vue component:
<template>
<div id="modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<slot name="header"></slot>
</div>
<div class="modal-body">
<slot></slot>
</div>
<div class="modal-footer">
<slot name="footer"></slot>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</template>
<script>
export default {
name: 'modal',
mounted() {
console.log('Modal mounted.')
},
data() {
return {}
},
props: ['id', 'booking_start', 'car', 'user'],
mounted() {
}
}
</script>
Laravel blade:
<div id="vue">
<modal v-bind="{{json_encode($reservation)}}">
<template slot="header">
<strong>Vehicle Checkout</strong>
</template>
<p>Ready to check out this vehicle?</p>
<table class="table table-sm">
<tr>
<th>Vehicle Name</th>
<td><span id="reservation-car-name">#{{ car.name }}</span></td>
</tr>
<tr>
<th>Vehicle Make / Model</th>
<td><span id="reservation-car-make-model"></span></td>
</tr>
<tr>
<th>Vehicle Registration</th>
<td><span id="reservation-car-registration"></span></td>
</tr>
<tr>
<th>Odometer Start</th>
<td><span id="reservation-car-odometer"></span></td>
</tr>
</table>
<template slot="footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Checkout</button>
</template>
</modal>
</div>
At this point, I am just attempting to get the data to show in the modal.
Looking at the Vue Dev tools:
There are no errors in the console, and I can output the data I am after in the console.
I'm probably missing something very basic as I am new to Vue, but I can't for the life of me work out what it is.
Component tag replaced by template content, so put all content into modal component from component tag <modal>.your content.</modal>
Vue.component('modal',{
props:['car'],
template: `<div><template slot="header">
<strong>Vehicle Checkout</strong>
</template>
<p>Ready to check out this vehicle?</p>
<table class="table table-sm">
<tr>
<th>Vehicle Name</th>
<td><span id="reservation-car-name">{{ car.name }}</span></td>
</tr>
<tr>
<th>Vehicle Make / Model</th>
<td><span id="reservation-car-make-model">{{ car.model }}</span></td>
</tr>
<tr>
<th>Vehicle Registration</th>
<td><span id="reservation-car-registration">{{ car.reg }}</span></td>
</tr>
<tr>
<th>Odometer Start</th>
<td><span id="reservation-car-odometer">{{ car.odo }}</span></td>
</tr>
</table>
<template slot="footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Checkout</button>
</template>
</div>`
})
const app = new Vue({
el: '#vue',
data() {
return {
id: '',
booking_start: '',
booking_end: '',
car: {name:'test1',model:'gh201',reg:'201821542',odo:'2018-01-01'},
user: []
};
},
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/js/bootstrap.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="vue">
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<modal :car="car"></modal>
</div>
</div>
</div>
</div>
My other answers related this issue : router view and transition-group

laravel 5.4/ vue js dont iterate my array

Hello I want to make a loop to iterate an array of data retrieve from a controller but I have an error message in vue js I can not find where is my error help me please I start with a vue js
here is my code
controller.php
public function index(){
$post= Posts::with('likes','comments', 'user')->orderBy('created_at','DESC')->get();
return $post ;
}
vue.js
const root = new Vue({
el: '#root',
data: {
msg: 'Update New Post:',
content: '',
posts: []
},
ready: function ready() {
this.created();
},
created: function created() {
var _this = this;
axios.get('http://localhost:8000/mur/posts')
.then(response => {
_this.posts = response.data;
//we are putting data into our posts array
console.log(response.data);
// show if success
Vue.filter('myOwnTime', function(value){
return moment(value).fromNow();
});
})
.catch(function (error) {
console.log(error); // run if we have error
});
}
},
view
<div v-for="post, key in posts">
<div class="col-md-12 col-sm-12 col-xs-12 all_posts">
<div class="col-md-1 pull-left">
<img :src="'{{asset('storage/avatar')}}/' + post.avatar"
style="width:50px;">
</div>
<div class="col-md-10" style="margin-left:10px">
<div class="row">
<div class="col-md-11">
<p><a :href="'{{url('profile')}}/' + post.slug" class="user_name"> #{{post.user.name}}</a> <br>
<span style="color:#AAADB3"> #{{ post.created_at }}
<i class="fa fa-globe"></i></span></p>
</div>
<div class="col-md-1 pull-right">
#if(Auth::check())
<!-- delete button goes here -->
<a href="#" data-toggle="dropdown" aria-haspopup="true">
{{--<img src="{{Config::get('app.url')}}/public/img/settings.png" width="20">--}}
</a>
<div class="dropdown-menu">
<li><a>some action here</a></li>
<li><a>some more action</a></li>
<div class="dropdown-divider"></div>
<li v-if="post.user_id == '{{Auth::user()->id}}'">
<a #click="deletePost(post.id)">
<i class="fa fa-trash"></i> Delete </a>
</li>
</div>
#endif
</div>
</div>
</div>
<p class="col-md-12" style="color:#000; margin-top:15px; font-family:inherit" >
#{{post.content}}
</p>
<div style="padding:10px; border-top:1px solid #ddd" class="col-md-12">
<!-- like button goes here -->
#if(Auth::check())
<div v-for="">
<div v-if="">
<p class="likeBtn" #click="likePost(post.id)">
<i class="fa fa-heart-o"></i>
</p>
</div>
</div>
data : #{{ post.likes.length }}
#endif
</div>
</div>
</div>
web.php
Route::get('mur/posts', 'PostController#index');
posts [ ] return this
[{"id":8,
"user_id":3,
"content":"content 1",
"status":0,
"created_at":"2017-12-27 22:43:20",
"updated_at":"2017-12-27 22:43:20",
"likes":[{"id":2,"posts_id":7,"user_id":3,"created_at":"2017-12-27 16:38:33","updated_at":null}],
"comments":[],
"user":{
"id":3,"name":"toto","sulg":"toto","email":"toto#hotmail.fr","avatar":"215563.jpg","is_actif":"activ\u00e9","created_at":"2017-12-06 15:30:42","updated_at":"2017-12-06 17:04:41"}
},
{"id":7,
"user_id":9,
"content":"coucou",
"status":0,
"created_at":"2017-12-27 16:07:01",
"updated_at":"2017-12-27 16:07:01",
"likes":[{"id":2,"posts_id":7,"user_id":4,"created_at":"2017-12-27 16:38:33","updated_at":null}],
"comments":[],
"user":{"id":9,"name":"blop","sulg":"blop","email":"blop#gmail.com","avatar":"logoBee.png","is_actif":"activ\u00e9","created_at":"2017-12-17 14:37:29","updated_at":"2017-12-17 14:37:29"}}
error in console

Paginate two collections + infiniteScroll

i'm having a trouble trying to paginate a view with 2 collections, i will explain.
i am using infiniteScroll (infinite-scrollDOTcom)
i don't have code on controller that i can reutilize to show i try with arrays but for infiniteScroll only with ajax and adding a route for it, but i dont like that ideia.
im trying to do something like this (pseudocode)
data = CollectionA + CollectionB
//if i can do it, try to orderBy (but not the most important now)
data->orderBy('something')
data->paginate(x)
return view()->with('data', data)
Controller (this is only to work with the infinite scroll for now):
public function getGarantias()
{
$data = GarantiaCasa::all()->toBase()->merge(GarantiaCarro::all()->toBase())->sortBy('nome');
$data = new Paginator($data, 1, 1);
//dd($data);
return view('administrador.garantias')
->with('garantias', $data);
}
infiniteScroll:
function infiniteScroll(message) {
var loading_options = {
finishedMsg: "<div class='end-msg'>"+message+"</div>",
msgText: "<div class='center'></div>",
img: '/img/loading.gif'
};
$('#items').infinitescroll({
loading : loading_options,
navSelector : "#data .pagination",
nextSelector : "#data .pagination li.active + li a",
itemSelector : "#items tr.item"
});
}
View (the 2 foreach is only for now until new solution
<div class="col-md-10 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body" id="data">
<div class="pull-right" onload="">
#foreach(Auth::user()->getAllSeguros() as $tiposeguro)
<div class="btn-group">
<span type="button" class="btn btn-default btn-filter" data-target="{{ $tiposeguro }}" >{{ ucfirst($tiposeguro) }}</span>
</div>
#endforeach
<div class="btn-group">
<button type="button" class="btn btn-default btn-filter" data-target="all">Todos</button>
</div>
</div>
<div class="table-container">
<table class="table table-filter">
<tbody id="items">
#foreach($garantiasCarro as $garantia)
<tr class="item" data-status="{{ $garantia->tipo }}" style="width: 500px">
<td>
<a href="#" class="pull-left">
<img src="{{ URL::to('/') }}/img/buttons/edit.png" class="media-photo">
</a>
</td>
<td>
<a href="#" class="pull-left">
<img src="{{ URL::to('/') }}/img/buttons/delete.png" class="media-photo">
</a>
</td>
<td>
<div class="media">
<div class="media-body">
<h4 class="title">
{{ $garantia->nome }}
<span class="pull-right tipo">({{ $garantia->tipo }})</span>
</h4>
<p class="summary">{{ $garantia->descricao }}</p>
</div>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<div hidden="hidden">{{ $garantias->links() }}</div>
</div>
</div>
</div>
UPDATE: now with the new Paginator i have sort of what i need but cant paginate, the infinitescroll doesnt work i think is probably because the links..
Thanks.

Resources