How to get articles and last 3 comments of each article?

|
DesolatorMagno 2020-03-19 15:37:33
That work for form
DesolatorMagno 2020-03-19 15:38:42
But we are talking about Ajax request.
2020-03-19 15:53:24
Has anyone here used js-emoji lib? I’m having a problem with that.

https://github.com/iamcal/js-emoji/issues/129

When use_sheet is true emojis are being disappeared · Issue #129 · iamcal/js-emojiGitHub
I’m trying to use App’s emojis, but when I set use_sheet true, emojis disappear. This is my code. emoji.img_set = ‘apple’; emoji.img_sets.apple.sheet = ‘http…
rijisoft 2020-03-19 16:40:20
Hi
Assume that
We have blog
Many articles
Each articles has many comments

How to get articles and last 3 comments of each article?
Something like this :
Article::latest()->with(‘last3_articles’)

DesolatorMagno 2020-03-19 16:41:18
Limit, take, order by.
DesolatorMagno 2020-03-19 16:43:37
Article::with(‘lastestPost’)->get()
DesolatorMagno 2020-03-19 16:44:07
You can order and limit inside the relationship.
DesolatorMagno 2020-03-19 16:45:19
WTF, obviously it can be eager loaded or lazy loaded.
rijisoft 2020-03-19 16:45:57
I think you don’t understand my question clearly
AngelGoitia 2020-03-19 16:46:10
How to put dynamic URL form
DesolatorMagno 2020-03-19 16:46:52
Your question is not 🚀 science, you want a model with another relationship with a limit and a specific order
DesolatorMagno 2020-03-19 16:49:59
You can call it OnlyLast3CommentsOrderByNewer
Article::with(‘OnlyLast3CommentsOrderByNewer’)->get()
If you want.
DesolatorMagno 2020-03-19 16:50:37
You can make a relationship that return that exact way.
rijisoft 2020-03-19 17:08:35
DesolatorMagno 2020-03-19 16:49:59
You can call it OnlyLast3CommentsOrderByNewer
Article::with(‘OnlyLast3CommentsOrderByNewer’)->get()
If you want.

I know what do you say but not working
comment in my app is a morph relation
so this is
return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘desc’)->take(5)->get();
not working

rijisoft 2020-03-19 17:09:31
rijisoft 2020-03-19 17:08:35
I know what do you say but not working
comment in my app is a morph relation
so this is
return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘desc’)->take(5)->get();
not working

production.ERROR: Method addEagerConstraints does not exist. {“userId”:27,”email”:”a@gmail.com”,”exception”:”[object] (BadMethodCallException(code: 0): Method addEagerConstraints does not exist.

rijisoft 2020-03-19 17:10:10
where is the problem?
DesolatorMagno 2020-03-19 17:10:12
Why get, and I think you should use limit.
rijisoft 2020-03-19 17:10:41
DesolatorMagno 2020-03-19 17:10:12
Why get, and I think you should use limit.

ok check it

rijisoft 2020-03-19 17:13:04
DesolatorMagno 2020-03-19 17:10:12
Why get, and I think you should use limit.

return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘desc’)->offset(0)->limit(5);
????

DesolatorMagno 2020-03-19 17:14:06
Why the offset? And yes I think that’s the way.
DesolatorMagno 2020-03-19 17:15:37
I am not in my PC now, so I can’t check.
rijisoft 2020-03-19 17:17:19
DesolatorMagno 2020-03-19 17:15:37
I am not in my PC now, so I can’t check.

return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘desc’)->limit(3);

rijisoft 2020-03-19 17:18:25
its working 😷😍
thanks 🥰🌺🌺🌺🌺👌🏻🤝🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
jnaghiloo 2020-03-19 17:47:32
There is any function like sync() to deleting just specific items?!
Sync will attach something, I will remove a record from pivot table

Done with detach()

Relaxed Guy 2020-03-19 18:12:13
guys has any one worked with google sheets
Relaxed Guy 2020-03-19 18:12:18
in laravel
Relaxed Guy 2020-03-19 18:12:47
is there an possibility of query a single to display ts information
MuntherHalwyat 2020-03-19 18:49:03
hello every body
MuntherHalwyat 2020-03-19 18:49:22
please , how can I fix this problem
MuntherHalwyat 2020-03-19 18:49:24
SQLSTATE[HY000] [1049] Unknown database ‘shopping’ (SQL: select * from information_s
chema.tables where table_schema = shopping and table_name = migrations and table_type = ‘BASE TABLE’)
MuntherHalwyat 2020-03-19 18:49:55
I use wamp server and mysql
MuntherHalwyat 2020-03-19 18:51:59
I added Schema::defaultStringLength(191); in AppServerProvider and same problem now
MuntherHalwyat 2020-03-19 18:52:48
and I tried all solutaions in google and stackoverflow
rijisoft 2020-03-19 21:10:33
something weird happened 🙂
this relation
return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘desc’)->limit(3);
work only for first article , for others return null;
i have 4 article
all of them more than 3 comments
this query only return for first article
if i delete article with id=1 ,, then return 3 comments for article with id =2 😐
rijisoft 2020-03-19 21:11:24
MuntherHalwyat 2020-03-19 18:49:24
SQLSTATE[HY000] [1049] Unknown database ‘shopping’ (SQL: select * from information_s
chema.tables where table_schema = shopping and table_name = migrations and table_type = ‘BASE TABLE’)

do you create database shopping?!

stefan_ssv 2020-03-19 21:54:37
RoNin9392 2020-03-19 14:11:22
Hi guys,
I am new to docker, I am trying to containerize my existing lumen app. But I have an issue, I am not albe to install dependency using composer. Here is my dockerfile. Can anyone help me with this ?

# Base Image
FROM php:7.3-apache

# Update base image and install required modules
RUN apt-get update && apt-get install -y
    libzip-dev
    libbz2-dev
    libjpeg62-turbo-dev
    libpng-dev
    libfreetype6-dev
    zip
    unzip
    && rm -r /var/lib/apt/lists/*
    && docker-php-ext-configure pdo_mysql –with-pdo-mysql=mysqlnd

# Install required extensions
RUN docker-php-ext-install mbstring tokenizer mysqli pdo_mysql gd

# Enable rewrite mod
RUN a2enmod rewrite

# Install composer
RUN curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin –filename=composer

# Set working directory
WORKDIR /var/www/html

# Copy application contents
COPY . .

# Install dependency
RUN composer install

# Expose port 80
EXPOSE 80

# Start application
CMD bash -c “php -S 0.0.0.0:8000 -t public”

You have strange copy statement here
And could you provide docker build output?

stefan_ssv 2020-03-19 21:56:23
sadeqi125 2020-03-19 11:51:48
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@ihs.tolosaadat.org to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at ts.edu.af Port 8

You have to look in server logs, in admin panel of your hosting

stefan_ssv 2020-03-19 21:59:10
MuntherHalwyat 2020-03-19 18:49:03
hello every body

Error tells you that there is no table in your database
Make sure you are connecting to right database
Or restore this table from your db backup archive

DesolatorMagno 2020-03-19 22:03:03
rijisoft 2020-03-19 21:10:33
something weird happened 🙂
this relation
return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘desc’)->limit(3);
work only for first article , for others return null;
i have 4 article
all of them more than 3 comments
this query only return for first article
if i delete article with id=1 ,, then return 3 comments for article with id =2 😐

If you take away the limit, does it work?

RoNin9392 2020-03-19 22:13:11
stefan_ssv 2020-03-19 21:54:37
You have strange copy statement here
And could you provide docker build output?

Actually docker build is successful, y didn’t get any error during build

RoNin9392 2020-03-19 22:14:30
stefan_ssv 2020-03-19 21:54:37
You have strange copy statement here
And could you provide docker build output?

But when I am trying to access the app in browser it gives me error regarding missing vendor

rijisoft 2020-03-19 22:15:05
DesolatorMagno 2020-03-19 22:03:03
If you take away the limit, does it work?

I don’t understand, what suggest to do?

DesolatorMagno 2020-03-19 22:16:07
Remove the limit in the relationship and try again.
DesolatorMagno 2020-03-19 22:16:57
You could also do a DD to the query to see it.
rijisoft 2020-03-19 22:18:52
DesolatorMagno 2020-03-19 22:16:07
Remove the limit in the relationship and try again.

I know that if I remove limit it’s work
But it’s not my answer
Think about for one article we have 25000 comments, but in this situation I only need 3 last comments

rijisoft 2020-03-19 22:21:40
rijisoft 2020-03-19 22:18:52
I know that if I remove limit it’s work
But it’s not my answer
Think about for one article we have 25000 comments, but in this situation I only need 3 last comments

In Instagram when you see a post
You only see a few comments , for each post

DesolatorMagno 2020-03-19 22:21:41
No matter what problem you face, you gotta first discover exactly what it is before fixing it, in not moment I told you to just use it like that, to load 3kk comments, I only am trying to help you find the error to fix the problem.

Is pretty safe to say is the limit that make that error, but better safe than sorry.

stefan_ssv 2020-03-19 22:30:05
RoNin9392 2020-03-19 22:13:11
Actually docker build is successful, y didn’t get any error during build

Im talking about output, not errors or exceptions

rijisoft 2020-03-19 22:50:44
DesolatorMagno 2020-03-19 22:21:41
No matter what problem you face, you gotta first discover exactly what it is before fixing it, in not moment I told you to just use it like that, to load 3kk comments, I only am trying to help you find the error to fix the problem.

Is pretty safe to say is the limit that make that error, but better safe than sorry.

in the case we have 3k comments
what’s the difference between
this return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘asc’)->limit(3);
and this return $this->morphMany(Reply::class ,’repliable’ )->orderBy(‘id’, ‘asc’)

i don’t want only solve problem , I want to find best solution

DesolatorMagno 2020-03-19 22:53:35
If the limit there give a problem, search for a alternative.
|