🇨🇳 Shenzhen,China・🕹Web developer
如果你喜欢我的项目并想支持我,点击这里 ❤️
👍 User-like features for Laravel Application.
🇨🇳 Shenzhen,China・🕹Web developer
如果你喜欢我的项目并想支持我,点击这里 ❤️
RT.
单独获取 某篇文章,这样是可以获取到用户信息的
$likers = $post->likers()->paginate(20);
foreach($likers as $user) {
// echo $user->name;
}
但是我如果 Get user likes with pagination:
$likes = $user->likes()->with('likable')->paginate(20);
foreach ($likes as $like) {
$like->likable; // App\Post instance
}
这种方式好像没有办法获取用户的详细信息,超哥是否有其他的方法?
May be it's not a issue but i was using your laravel follow unfollow package and it's working fine but when i try to install the like package and try to publish the configuration and the migration it says that the file is not found and when i try to create the like it always throws an exception saying => Class name must be a valid object or a string <= but the both models are configured as the instruction given also the post and the user are both objects when i check dd it.
Composer fails installing, audit throws this message:
+-------------------+----------------------------------------------------------------------------------+
| Package | guzzlehttp/guzzle |
| CVE | CVE-2022-31091 |
| Title | Change in port should be considered a change in origin |
| URL | https://github.com/guzzle/guzzle/security/advisories/GHSA-q559-8m2m-g699 |
| Affected versions | >=7,<7.4.5|>=4,<6.5.8 |
| Reported at | 2022-06-20T22:24:00+00:00 |
+-------------------+----------------------------------------------------------------------------------+
+-------------------+----------------------------------------------------------------------------------+
| Package | guzzlehttp/guzzle |
| CVE | CVE-2022-31090 |
| Title | CURLOPT_HTTPAUTH option not cleared on change of origin |
| URL | https://github.com/guzzle/guzzle/security/advisories/GHSA-25mq-v84q-4j7r |
| Affected versions | >=7,<7.4.5|>=4,<6.5.8 |
| Reported at | 2022-06-20T22:24:00+00:00 |
Just love you for your open source effort!
Can you please also create a separate Follow package without relation type column?
It will be more scalable for millions of users.
Thanks again.
BYE
I attempted to use this packages attachLikeStatus on a cursorPaginated eloquent model. Which doesn't seem to work. With normal pagination it works fine.
$listings = Listing::filterByRequest($request)
->cursorPaginate($perPage);
$currentUser = Auth::user();
if (Auth::check()) {
$listings = $currentUser->attachLikeStatus($listings);
}
I added a CursorPaginator handler to Liker.php trait and now the above works:
case $likeables instanceof CursorPaginator:
$likeables = \collect($likeables->items());
break;
This package doesn't seem to create or publish migrations in my Laravel 9 installation.
The command php artisan vendor:publish --provider="Overtrue\\LaravelLike\\LikeServiceProvider" --tag=migrations
throws a warning: No publishable resources for tag [migrations].
The warning is the same for --tag=configs
as well.
Also, I might be wrong, but the package doesn't create a default likes table migration which I can use. Do I have to manually create a likes table or is the package supposed to create a default migration for me?
超哥
假如我想分页获取 like 过的全部数据、该怎样实现
I would recommend to add likes relationship:
public function likes(): \Illuminate\Database\Eloquent\Relations\MorphMany
{
return $this->morphMany(config('like.like_model'), 'likeable');
}
In the same way as you did in Favorites. It is useful for delete all linked likes to the object, etc.
It Returns an error when i try to do this. Can you tell me a way to use it @overtrue
hello
In my app the user has a company profile in addition to the his profile ( like Facebook pages).
I need to like a Post by this company profile using company_id for example.
How to implement that with your package please ?
thanks
On my blade page I have {{ $post->likes()->count() }} to display the number of current likes however when I refresh the page I get the error: Method Illuminate\Database\Eloquent\Collection::likes does not exist.
To my understanding Im not using that so unsure why it wont find the function im looking for.
Any help would be appreciated.
Jamie
"message": "Call to undefined method Illuminate\Database\Eloquent\Builder::like()",
"exception": "BadMethodCallException",
......
Post Controller:
public function likePost($id)
{
$user = User::where('id', auth()->user()->id);
$post = Post::find($id);
$user->like($post);
return response(['message' => 'Post Like successfully!']);
}
Post Model:
After upgrading the package from 2.0 to 4.0, the following error displayed in the post index view:
Querying the posts via Laravel as follows:
$posts = Post::withCount('likes')
->whereIn('user_id', function ($query) {
$query->select('following_id')
->from('user_follower')
->where('follower_id', auth()->id());
})->orWhere('user_id', auth()->id())
->latest()
->paginate(10);
Created like button as a Vue component to display the count and update it when a post is liked or unliked.
The count from the Post model is fetched via "likes_count" attribute.
Issue appears to be a bug in the package.
Please note that I extended the package traits CanLiked, CanBeLiked in my App/Libraries/Like namespace. Then used the extended traits in the target models. Thanks
If user has 5 posts and each post has 5 likes, so there should be all posts total likes = 25.
I think it should like this
$user()->totalLikes()->count()
$posts = Post::with('post_images')->with('user')->withCount('comments')->orderBy('created_at', 'desc')->get();
how to get total likes for each post?
thank you
Hi, I would like to know how to get the last id entered by this function?
$like = $request->user()->like($item);
$like->id not working
Call to a member function hasLiked() on int
解决不了问题,还是自己开发吧。谢谢啦
Is User modal can be likeable and liker?
Hi, can you delete this line of code on purpose only published migration that can be migrated?
laravel-like/src/LikeServiceProvider.php
Line 23 in ce78074
Thank you.
// likers count
$post->likers;
The likers count always returning empty collection!
However overwriting writing the relation method like this works fine:
public function likers()
{
return $this->morphToMany(User::class, 'likable', 'likes');
}
It is working well in laravel-follow used branch. Please help!
Hi,
I'm running into an issue where I have a Page
model that can like something.
but unfortunately, as I noticed the Liker can only be the user model.
Any suggestion?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.