Undefined variable in query builder












0















I have a problem with a eloquent query.
When i run the query i get back Undefined variable: ccid



i have pass the ccic via function



public function index($category)
{
$currentuser = auth()->user();
$ccid = $currentuser->clientcat_id;

$products = DB::table('products')
->join('resomes', 'products.pricingcat_id', '=', 'resomes.pricingcat_id')
->join('users', function ($join) {
$join->on('resomes.clientcat_id', '=', 'users.clientcat_id')
//->where('users.clientcat_id', '=', 1);
->where(function($q) use($ccid){
$q->where('users.clientcat_id', '=', $ccid);
}
);
})
->select('products.*', 'resomes.discount', DB::raw('(products.price - (products.price * (resomes.discount/100))) as cPrice'))
->where('products.ccat_id', '=', $category)
//->where(function($q) use($category){ $q->where('products.ccat_id', '=', $category);})
->orderBy('products.ccat_id', 'ASC')
->orderBy('products.price', 'ASC')
->paginate(config('pelma.products_list_pagination'));

//print_r($products);
return view('client.products.list', compact('products'));
}


Anyone have an idea?
Thank you very much










share|improve this question

























  • ->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.

    – Csaba Gergely
    Jan 19 at 12:10


















0















I have a problem with a eloquent query.
When i run the query i get back Undefined variable: ccid



i have pass the ccic via function



public function index($category)
{
$currentuser = auth()->user();
$ccid = $currentuser->clientcat_id;

$products = DB::table('products')
->join('resomes', 'products.pricingcat_id', '=', 'resomes.pricingcat_id')
->join('users', function ($join) {
$join->on('resomes.clientcat_id', '=', 'users.clientcat_id')
//->where('users.clientcat_id', '=', 1);
->where(function($q) use($ccid){
$q->where('users.clientcat_id', '=', $ccid);
}
);
})
->select('products.*', 'resomes.discount', DB::raw('(products.price - (products.price * (resomes.discount/100))) as cPrice'))
->where('products.ccat_id', '=', $category)
//->where(function($q) use($category){ $q->where('products.ccat_id', '=', $category);})
->orderBy('products.ccat_id', 'ASC')
->orderBy('products.price', 'ASC')
->paginate(config('pelma.products_list_pagination'));

//print_r($products);
return view('client.products.list', compact('products'));
}


Anyone have an idea?
Thank you very much










share|improve this question

























  • ->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.

    – Csaba Gergely
    Jan 19 at 12:10
















0












0








0








I have a problem with a eloquent query.
When i run the query i get back Undefined variable: ccid



i have pass the ccic via function



public function index($category)
{
$currentuser = auth()->user();
$ccid = $currentuser->clientcat_id;

$products = DB::table('products')
->join('resomes', 'products.pricingcat_id', '=', 'resomes.pricingcat_id')
->join('users', function ($join) {
$join->on('resomes.clientcat_id', '=', 'users.clientcat_id')
//->where('users.clientcat_id', '=', 1);
->where(function($q) use($ccid){
$q->where('users.clientcat_id', '=', $ccid);
}
);
})
->select('products.*', 'resomes.discount', DB::raw('(products.price - (products.price * (resomes.discount/100))) as cPrice'))
->where('products.ccat_id', '=', $category)
//->where(function($q) use($category){ $q->where('products.ccat_id', '=', $category);})
->orderBy('products.ccat_id', 'ASC')
->orderBy('products.price', 'ASC')
->paginate(config('pelma.products_list_pagination'));

//print_r($products);
return view('client.products.list', compact('products'));
}


Anyone have an idea?
Thank you very much










share|improve this question
















I have a problem with a eloquent query.
When i run the query i get back Undefined variable: ccid



i have pass the ccic via function



public function index($category)
{
$currentuser = auth()->user();
$ccid = $currentuser->clientcat_id;

$products = DB::table('products')
->join('resomes', 'products.pricingcat_id', '=', 'resomes.pricingcat_id')
->join('users', function ($join) {
$join->on('resomes.clientcat_id', '=', 'users.clientcat_id')
//->where('users.clientcat_id', '=', 1);
->where(function($q) use($ccid){
$q->where('users.clientcat_id', '=', $ccid);
}
);
})
->select('products.*', 'resomes.discount', DB::raw('(products.price - (products.price * (resomes.discount/100))) as cPrice'))
->where('products.ccat_id', '=', $category)
//->where(function($q) use($category){ $q->where('products.ccat_id', '=', $category);})
->orderBy('products.ccat_id', 'ASC')
->orderBy('products.price', 'ASC')
->paginate(config('pelma.products_list_pagination'));

//print_r($products);
return view('client.products.list', compact('products'));
}


Anyone have an idea?
Thank you very much







laravel eloquent laravel-5.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 11:59







Kostas Giannopoulos

















asked Jan 19 at 11:44









Kostas GiannopoulosKostas Giannopoulos

103




103













  • ->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.

    – Csaba Gergely
    Jan 19 at 12:10





















  • ->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.

    – Csaba Gergely
    Jan 19 at 12:10



















->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.

– Csaba Gergely
Jan 19 at 12:10







->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.

– Csaba Gergely
Jan 19 at 12:10














2 Answers
2






active

oldest

votes


















0














You didn't pass $ccid to



->join('users', function ($join)


you have to use $ccid to this function also.






share|improve this answer
























  • oohh! I had check my code 30 times and i did not see it! THANK you very much Niral! You save my time! Thanks again

    – Kostas Giannopoulos
    Jan 19 at 12:15



















0














You can do someting like this




->join('users', function ($join) use ($ccid) {




and explaination is here In PHP, what is a closure and why does it use the "use" identifier?






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54266715%2fundefined-variable-in-query-builder%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You didn't pass $ccid to



    ->join('users', function ($join)


    you have to use $ccid to this function also.






    share|improve this answer
























    • oohh! I had check my code 30 times and i did not see it! THANK you very much Niral! You save my time! Thanks again

      – Kostas Giannopoulos
      Jan 19 at 12:15
















    0














    You didn't pass $ccid to



    ->join('users', function ($join)


    you have to use $ccid to this function also.






    share|improve this answer
























    • oohh! I had check my code 30 times and i did not see it! THANK you very much Niral! You save my time! Thanks again

      – Kostas Giannopoulos
      Jan 19 at 12:15














    0












    0








    0







    You didn't pass $ccid to



    ->join('users', function ($join)


    you have to use $ccid to this function also.






    share|improve this answer













    You didn't pass $ccid to



    ->join('users', function ($join)


    you have to use $ccid to this function also.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 19 at 12:07









    Niral PatelNiral Patel

    616




    616













    • oohh! I had check my code 30 times and i did not see it! THANK you very much Niral! You save my time! Thanks again

      – Kostas Giannopoulos
      Jan 19 at 12:15



















    • oohh! I had check my code 30 times and i did not see it! THANK you very much Niral! You save my time! Thanks again

      – Kostas Giannopoulos
      Jan 19 at 12:15

















    oohh! I had check my code 30 times and i did not see it! THANK you very much Niral! You save my time! Thanks again

    – Kostas Giannopoulos
    Jan 19 at 12:15





    oohh! I had check my code 30 times and i did not see it! THANK you very much Niral! You save my time! Thanks again

    – Kostas Giannopoulos
    Jan 19 at 12:15













    0














    You can do someting like this




    ->join('users', function ($join) use ($ccid) {




    and explaination is here In PHP, what is a closure and why does it use the "use" identifier?






    share|improve this answer






























      0














      You can do someting like this




      ->join('users', function ($join) use ($ccid) {




      and explaination is here In PHP, what is a closure and why does it use the "use" identifier?






      share|improve this answer




























        0












        0








        0







        You can do someting like this




        ->join('users', function ($join) use ($ccid) {




        and explaination is here In PHP, what is a closure and why does it use the "use" identifier?






        share|improve this answer















        You can do someting like this




        ->join('users', function ($join) use ($ccid) {




        and explaination is here In PHP, what is a closure and why does it use the "use" identifier?







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 19 at 13:01

























        answered Jan 19 at 12:56









        FilFil

        1,40032137




        1,40032137






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54266715%2fundefined-variable-in-query-builder%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre