I have an article application. Normally I do not have any recommendation system other than getting latest 100 data from database and than recommending them depending on like count. I wonder how I can get the data into an array and than do some math before outputing. I have an idea but couldn't find anything useful about how to do it in the internet.
So lets say I have this query:
$articles = Article::orderBy('id', 'desc')->take(100)->get();
Now what I want to do is creat another array
with size of 100 and place each article id one by one but depending on my algorithm.
before I start I want to give you everything that will be used:
$article->likecount
$article->viewcount
$article->user->reputation
$article->category->interest
I will use these values in orther to re-order last 100 articles and than paginate
them.
Here is what I need:
- I need to get
$article->likecount
- Add
$user->reputation
- Add the
$category->interest
Result
minus$article->viewcount
And than put this value inside the array. Array needs to be ordered smallest to the largest.
I can do something simular in C or C++ but I do not know enough syntax to accomplish this in raw PHP or Laravel
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire