Undefined variable in query builder
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
add a comment |
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
->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.
– Csaba Gergely
Jan 19 at 12:10
add a comment |
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
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
laravel eloquent laravel-5.7
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
add a comment |
->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
add a comment |
2 Answers
2
active
oldest
votes
You didn't pass $ccid to
->join('users', function ($join)
you have to use $ccid to this function also.
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
add a comment |
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?
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You didn't pass $ccid to
->join('users', function ($join)
you have to use $ccid to this function also.
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
add a comment |
You didn't pass $ccid to
->join('users', function ($join)
you have to use $ccid to this function also.
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
add a comment |
You didn't pass $ccid to
->join('users', function ($join)
you have to use $ccid to this function also.
You didn't pass $ccid to
->join('users', function ($join)
you have to use $ccid to this function also.
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
add a comment |
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
add a comment |
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?
add a comment |
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?
add a comment |
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?
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?
edited Jan 19 at 13:01
answered Jan 19 at 12:56
FilFil
1,40032137
1,40032137
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
->join('users', function ($join) use($ccid) {...}) You must pass the variable into the scope.
– Csaba Gergely
Jan 19 at 12:10