GithubHelp home page GithubHelp logo

Comments (20)

overtrue avatar overtrue commented on June 9, 2024
$user = Auth::user()->id; 
$user->follow($professional);

$user is an integer, not an object.

from laravel-follow.

 avatar commented on June 9, 2024

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.

overtrue avatar overtrue commented on June 9, 2024

plz paste the User and Professional Model used traits.

from laravel-follow.

 avatar commented on June 9, 2024

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.

overtrue avatar overtrue commented on June 9, 2024

Did you confirmed that $user->follow($professional) was processed?

from laravel-follow.

 avatar commented on June 9, 2024

I checked in the database and nothing has been added.

from laravel-follow.

overtrue avatar overtrue commented on June 9, 2024

you can test it in Tinker:

$user = User::find(1);
$professional = Professional::find(1); 

$user->follow($professional); 

from laravel-follow.

 avatar commented on June 9, 2024

That adds a record in the database when i followed your code and tested in tinker

from laravel-follow.

 avatar commented on June 9, 2024

Here is the link with the screenshot https://ibb.co/fbLhCn

from laravel-follow.

overtrue avatar overtrue commented on June 9, 2024

so, plz check you controller code.

from laravel-follow.

 avatar commented on June 9, 2024
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.

overtrue avatar overtrue commented on June 9, 2024

Sorry, You can using dd() function to debug you code, confirm every variable is expected.

from laravel-follow.

 avatar commented on June 9, 2024

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.

overtrue avatar overtrue commented on June 9, 2024

dd($professional);

from laravel-follow.

 avatar commented on June 9, 2024

I mean dd($professional); gives me a null. Here are the screenshots

  1. https://ibb.co/ijUCdS
  2. https://ibb.co/f14657

and the code

public function followProfessional($slug)
    {
      $professional = Professional::where('slug', $slug)->first();
      
      $user = Auth::user();
      $user->follow($professional);
      dd($professional);
    }

from laravel-follow.

overtrue avatar overtrue commented on June 9, 2024

So, The result is you Professional::where('slug', $slug)->first() cannot find the $professional.

from laravel-follow.

overtrue avatar overtrue commented on June 9, 2024

every thing is OK, but problem is there is no matched slug professional exists.

from laravel-follow.

 avatar commented on June 9, 2024

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.

 avatar commented on June 9, 2024

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.

overtrue avatar overtrue commented on June 9, 2024

😆

from laravel-follow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.