Comments (20)
$user = Auth::user()->id;
$user->follow($professional);
$user
is an integer, not an object.
from laravel-follow.
So how to solve this? I'm stuck at this point
i also tried $user = Auth::user();
But that doesn't add anything to the database either
from laravel-follow.
plz paste the User and Professional Model used traits.
from laravel-follow.
User.php
use Overtrue\LaravelFollow\Traits\CanFollow; use Overtrue\LaravelFollow\Traits\CanLike; use Overtrue\LaravelFollow\Traits\CanFavorite; use Overtrue\LaravelFollow\Traits\CanVote; use CanFollow; use CanLike; use CanFavorite; use CanVote;
Professional.php
use Overtrue\LaravelFollow\Traits\CanBeFollowed; use Overtrue\LaravelFollow\Traits\CanBeLiked; use CanBeLiked; use CanBeFollowed;
from laravel-follow.
Did you confirmed that $user->follow($professional)
was processed?
from laravel-follow.
I checked in the database and nothing has been added.
from laravel-follow.
you can test it in Tinker:
$user = User::find(1);
$professional = Professional::find(1);
$user->follow($professional);
from laravel-follow.
That adds a record in the database when i followed your code and tested in tinker
from laravel-follow.
Here is the link with the screenshot https://ibb.co/fbLhCn
from laravel-follow.
so, plz check you controller code.
from laravel-follow.
public function followProfessional($slug)
{
$professional = Professional::where('slug', $slug)->first();
if(! $professional) {
return redirect()->back()->with('error', 'Professional does not exist.');
}
$user = Auth::user();
$user->follow($professional);
return redirect()->back()->with('success', 'You are currently following this professional.');
}
Is this code right? I know im making a mistake somewhere
from laravel-follow.
Sorry, You can using dd() function to debug you code, confirm every variable is expected.
from laravel-follow.
When i removed this from the controller code above, it adds a record but adds a 0 in followable_id
if(! $professional) {
return redirect()->back()->with('error', 'Professional does not exist.');
}
dd() gives me a null displayed nothing else
from laravel-follow.
dd($professional);
from laravel-follow.
I mean dd($professional); gives me a null. Here are the screenshots
and the code
public function followProfessional($slug)
{
$professional = Professional::where('slug', $slug)->first();
$user = Auth::user();
$user->follow($professional);
dd($professional);
}
from laravel-follow.
So, The result is you Professional::where('slug', $slug)->first()
cannot find the $professional
.
from laravel-follow.
every thing is OK, but problem is there is no matched slug professional exists.
from laravel-follow.
But if you see in the image 1. i sent. When i tested in the tinker it added App\Models\Professional to the followable type but when i tried with the code above from view button it added App\Models\User;
Is that also an error?
from laravel-follow.
I changed the code to
public function followProfessional(ProfessionalCategory $professionalcategory, $slug)
{
$professional = Professional::where('slug', $slug)->first();
$user = Auth::user();
$user->follow($professional);
dd($professional);
}
and now dd shows
Professional {#378 ▼
#appends: array:1 [▶]
#table: "professionals"
#fillable: array:27 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:33 [▶]
#original: array:33 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
#forceDeleting: false
#autoTagTmp: null
#autoTagSet: false
And the record is added to the database with the right followable type App\Models\Professional
Thank you so much @overtrue for your valuable time.
I really love your package. More than that the support you provided here. Wonderful
from laravel-follow.
😆
from laravel-follow.
Related Issues (20)
- Making follows polymorphic HOT 11
- 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
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.