Comments (13)
If you are using id to created data, you must put the second argument like this:
$post: id: 119
// using id
$user->toggleLike(119, 'App\Post');
// using model
$user->toggleLike($post);
So, plz update the following line:
$user->toggleLike($postid);
to
$user->toggleLike($postid, Post::class);
from laravel-follow.
Auth::user()->hasLiked(119, 'App\Post')
from laravel-follow.
I tried this, but still it's returning false. Any other solutions please
from laravel-follow.
Looks like your database is a user liked another user, not liked a post.
from laravel-follow.
Please review this snapshot.
The followable type is App\User in the database table. Where did I do wrong?
from laravel-follow.
yes, it means user:1 liked user:119
from laravel-follow.
$user = App\User::find(1);
dd($user->hasLiked(119)); // true
from laravel-follow.
But user:119 doesn't exists in the database. Also, when I do (Auth::user()->hasLiked(119, 'App\User')
It also returns false
.
from laravel-follow.
How does you inserted the data? can you show me the code?
from laravel-follow.
User Model:
use Overtrue\LaravelFollow\Traits\CanBeFollowed;
use Overtrue\LaravelFollow\Traits\CanFollow;
use Overtrue\LaravelFollow\Traits\CanLike;
class User extends Authenticatable
{
use CanFollow, CanBeFollowed, CanLike;
Post Model
use Overtrue\LaravelFollow\Traits\CanBeLiked;
class Post extends Model
{
use CanBeLiked;
Controller
public function likePost($postid)
{
$user = Auth::user();
$user->toggleLike($postid);
return Response::json(array(
'success' => true
));
//return redirect()->back()->with('message', 'Liked');
}
And the route has a get method to call likePost
function
from laravel-follow.
https://github.com/overtrue/laravel-follow#parameters
from laravel-follow.
Thanks. It worked.
from laravel-follow.
😄
from laravel-follow.
Related Issues (20)
- Getting same error in Model all the time HOT 7
- Error Traits HOT 9
- Get List of Followings users HOT 1
- config key typo HOT 2
- Question: How to send notification/email to user when they have a new follower? HOT 11
- get General error: 1 no such table: followables error HOT 12
- $user->followings not working properly HOT 6
- how to recover data from the "following" user? HOT 2
- Feature Request: Followers you know HOT 9
- Extending the model
- Trait "Overtrue\LaravelFollow\Traits\Followable" not found HOT 2
- Update for Laravel 10
- [ERROR] After running command - SSL Issues HOT 3
- php artisan vendor:publish does not publish the migration or config HOT 3
- Error after upgrade to 5.1.0 HOT 14
- wrong sample code in readme.
- Can't Get Following Model Data HOT 1
- getting "general error" when attempting to use UUIDs HOT 2
- sorry. please delete this issue
- has_followed没有实现 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-follow.