vendredi 5 avril 2019

How to call a function in one controller to the other controller in laravel

I want to call a function in another controller. when i call this gives me an error.

Call to undefined method Illuminate\Database\Query\Builder::defaultBuckets()

I dont know why it gives me this error. I don't know i am calling this function rightly in another controller. Here is my code. Please Help.

Here is my function i created in my BucketController:

public function defaultBuckets()
{
    $buckets = Bucket::where('bucket_type', 'default')->get();
}

And here is my Profile controller function Where i call this function:

public function show(User $user)
{
    $authUser = JWTAuth::parseToken()->toUser();

    if (! $user->isBlocking($authUser) && ! $user->isBlockedBy($authUser)) {
        if($authUser->id == $user->id){

           $profile = $user->where('id', $user->id)->defaultBuckets()->with([
            'posts', 'likes', 'followers', 'following'])->first(); 
        } else{

        $profile = $user->where('id', $user->id)->with([
            'posts' => function ($query) {
                $query->where('post_type', 'public');
            },
            'buckets' => function ($query) {
                $query->where('bucket_type', 'public');
            },
            'likes' => function ($query) {
                $query->where('post_type', 'public');
            },
            'followers', 'following'])->first();
    }
    return response()->json(['profile'=> $profile], 200);
    }

    return response()->json(['message'=> 'Your are not able to open profile of this user'], 200);
} 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire