I am experience this error when I try to paginate a blog post using laravel 5
Call to undefined method Illuminate\Database\Eloquent\Collection::render()
Kindly assist on this issue
this is very simple , you just need to pass collection of data from controller to view with paginate(number) for example in my project i pass collection of brand data with this line of code $brands = Brand::where('name', 'LIKE', '%'.$category.'%')->latest()->paginate(5); and now view can render each 5 object.
Related
I'm using knex stream interface to stream the data from the table which has lot of records. I want to run some javascript code in each object of the array to modify the object and add extra parameters to the object. So, basically I'm trying to map through the stream and update the objects in the array before pipe it to the response in the api.
I tried something like -
pg('someTable').where(someCondition).pipe(JSONStream.parse()).map((item)=>{
//updating the object
return item
}).pipe(res)
But it's not working. I'm not sure how to do it. Can someone please help me with this?
Thanks in advance :)
I could not find a good template for the update method for the xdevapi library and thought maybe some one could help me out with getting this to work.
acts_table
.update()
.set('account_status', 'new account status')
.where('customer_number like :customer_number && original_account_number like :original_account_number')
.bind('01234588456')
.bind('12156464645')
.execute()
I think its just a formatting issue, but with no real examples in the XDEVAPI Documentation for update for Javascript I'm kind of at a lost. Please help. The error I get is Cannot Read property 'toArray' of undefined.
It was formatting, in the bind method I forgot to put the fields we were binding so the answer is this:
acts_table
.update()
.set('account_status', 'new account status')
.where('customer_number like :customer_number && original_account_number like :original_account_number')
.bind('customer_number','01234588456')
.bind('original_account_number', '12156464645')
.execute()
i am using Strapi for a prototype and i am meeting the following issue. I have created a new content type "Checklist" and i added in it a relation property 1 to many with the User model provided by the users-permissions plugin.
Then i wanted to add some custom logic on the lifecycle call back, in beforeSave and in beforeUpdate from which i would like to access the user assigned to the Checklist.
The code looks like that:
{
var self = module.exports = {
// Before saving a value.
// Fired before an `insert` or `update` query.
generateLabel : (model) => {
var label = "";
var day = _moment(model.date,_moment.ISO_8601).year();
var month = _moment(model.date,_moment.ISO_8601).day();
var year = _moment(model.date,_moment.ISO_8601).month();
console.log(model);
if (model.user) {
label = `${model.user}-${year}-${month}-${day}`;
}else{
label = `unassigned-${year}-${month}-${day}`;
}
return label;
I call the method generateLabel from the callback. It works, but my model.user always returned undefined. It is a 1-n property. I can access model.date property (one of the field i have created) without any issue, so i guess the pbs is related to something i have to do to populate the user relation, but i am not sure on how to proceed.
When i log the model object, the console display what i guess is a complete mongoose object but i am not sure where to go from there as if i try to access the property that i see in the console, i will always reach an undefined.
Thanks in advance for your time, i use the following
strapi: 3.0.0-alpha.13.0.1
nodejs: v9.10.1
mongodb: 3.6.3
macos high sierra
Also running into the similar / same issue, I think this has to do with the user permissions plugin, and having to use that to access the User model. Or I thought about trying to find the User that’s associated with the id of the newly created record. I’m trying to use AfterCreate. Anyone that could shed some light on this would be great!
It's because relational attributes are not send in create fonction (See your checklist service add function).
Relations are handled in an other function updateRelations.
The thing you can do is to send values in Checklit.create()
I'm using Loopback v3, and when I try to reference another model inside
another one, eg. customer.js, with
module.exports = function(Customer) {
var Product = Customer.app.models.Product;
it crashes saying
TypeError: Cannot read property 'models' of undefined
Any thoughts?
Have you added a relation between both models?
Make sure you have defined a relation between Customer and Product models on Customer.json and Product.json.
This can be done manually or by using the loopback generator.
slc loobpack:relation
More information here: http://loopback.io/doc/en/lb2/Creating-model-relations.html
Dear stackoverflow community,
I usually no make posts here, but in this time i ask myself why not?, after 2 hours without getting a solution.
This one is pretty basic but involves a specific json model, mongoose, mongodb and nodejs.
Now the problem, is that i´m trying to get the data for the user_ppal_id : 1 and the exam_design_id : 1 , the search of the user_ppal_id succeeded, but the exam_design_id that is into a nested array always returns to me the value 1 and 2 (and i´m passing by parameter the exam_design_id 1)...
This is my model, My nodejs rest method and how i´m using mongoose, nodejs and mongodb, My moongose model, A better view of the model from Umongo Ide:
SEE THE IMAGE HERE BECAUSE I AM NEW IN STACKOVERFLOW
All the structure is working, but the data from result is not the one i expected. You can check the response of this rest service by just clicking this url: http://207.244.75.230:8000/dyntestreports/getExamReport?idUserPpal=1&idExamDesign=1
In the response i´m getting the exam_design_id data for values 1 and 2 when i pass just the value 1.
Actually i tried with the following mongo queries and i not succeed:
1) ExamReportByUser.find({'user_ppal_id':userPpalId,'exams_created': {$elemMatch:{'exam_design_id': {$eq:examDesignId}}}}
2)ExamReportByUser.find({'user_ppal_id':userPpalId,'exams_created.0.exam_design_id':examDesignId}
At this moment i don´t know what i´m doing wrong even from a mongo console query i can´t get it works for just exam_design_id = 1 data.
I´m sure it could be a simple error but i´m not seeing it at this moment.
I really hope you can help me guys. Thanks in advance! Have a nice day.
My bad! I just have found the solution... And i post it here for anyone that had the same doubt... The code querying the data should be like this (it was just keys syntax, basic mongo):
ExamReportByUser.find({'user_ppal_id':userPpalId},{'exams_created': {$elemMatch:{'exam_design_id': examDesignId}}},'id user_ppal_id exams_created exam_design_id user_submitted_exam',function(err, result) { if (err) return console.log(err); return res.send(result); }); };
Now i´m getting the data of user 1 and exam_design 1.
I will not select this as an answer, waiting for the specialists ;)