Get value from select field and compare against databaseHow do I get a YouTube video thumbnail from the YouTube API?How to get multiple selected values of select box in php?Get value from SimpleXMLElement Objectselecting unique values from a columnCreating default object from empty value in PHP?PHP ForEach get max valueHow to include different blade template view in if-else clause in Laravel?Compare get values with one of the value of fields from databaseBest practise populate Bootstrap HTML form SELECT dropdown with values from databaseAdd product dropdown selected value as cart item meta data in Woocommerce
Find the radius of the hoop.
How can a valley surrounded by mountains be fertile and rainy?
Is is okay to submit a paper from a master's thesis without informing the advisor?
Why wasn't ASCII designed with a contiguous alphanumeric character order?
Just graduated with a master’s degree, but I internalised nothing
Resolve this Fibonacci Relationship
If two black hole event horizons overlap (touch) can they ever separate again?
Closest Proximity of Oceans to Freshwater Springs
What's the safest way to inform a new user of their password on an invite-only website?
What kind of jet plane is this?
Was it really unprofessional of me to leave without asking for a raise first?
What is "override advice"?
Prime parity peregrination
How to securely dispose of a smartphone?
How do I organize members in a struct to waste the least space on alignment?
Journal standards vs. personal standards
What verb for taking advantage fits in "I don't want to ________ on the friendship"?
Using “ser” without "un/una"?
Most elegant way to write a one-shot 'if'
Are the requirements of a Horn of Valhalla cumulative?
How did researchers find articles before the Internet and the computer era?
Put my student loan in parents’ second mortgage - help?
Is it possible to have a character with proficiency in all martial weapons without proficiency in Medium armor?
Is there reliable evidence that depleted uranium from the 1999 NATO bombing is causing cancer in Serbia?
Get value from select field and compare against database
How do I get a YouTube video thumbnail from the YouTube API?How to get multiple selected values of select box in php?Get value from SimpleXMLElement Objectselecting unique values from a columnCreating default object from empty value in PHP?PHP ForEach get max valueHow to include different blade template view in if-else clause in Laravel?Compare get values with one of the value of fields from databaseBest practise populate Bootstrap HTML form SELECT dropdown with values from databaseAdd product dropdown selected value as cart item meta data in Woocommerce
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
What I'm needing:
Using the following DB column clay_plan_type
+----+------------------+
| id | clay_plan_type |
+----+------------------+
| 5 | Single Shooter |
| 6 | Lunch Sponsor |
| 7 | Beverage Sponsor |
+----+------------------+
I want to disable the select options in my form if the value of my select field matches the value in clay_plan_type
View example:
@if ($sponsortype === "Beverage Sponsor")
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
etc...
Controller Example:
$sponsortype = DB::table('clay_shoots')->select('clay_plan_type')->get();
return view('clayshoot.sponsorform',compact('sponsortype'));
When I dd($sponsortype);
I get the following:
Collection #855 ▼
#items: array:3 [▼
0 => #801 ▼
+"clay_plan_type": "Single Shooter"
1 => #802 ▼
+"clay_plan_type": "Lunch Sponsor"
2 => #803 ▼
+"clay_plan_type": "Beverage Sponsor"
]
I get no errors when running the if statement
in the view, but I don't get the correct results. It acts as the `if statement is not there.
So I try adding $sponsortype->clay_plan_type
and I get the error:
Property [clay_plan_type] does not exist on this collection instance.
If I run in a foreach loop
this works in the View but I get multiple repeats of the same item in the select field. (See below image)
@foreach($sponsortype as $st)
@if ($st->clay_plan_type == "Beverage Sponsor" )
YUP
@else
NOPE
@endif
@endforeach
// OUTPUT: NOPE NOPE YUP ("Beverage Sponsor" is the last record in the table)
Hope I'm explaining this in a way you understand. If you need more info, please let me know. Any help in figuring this out would be appreciated.
php laravel
add a comment |
What I'm needing:
Using the following DB column clay_plan_type
+----+------------------+
| id | clay_plan_type |
+----+------------------+
| 5 | Single Shooter |
| 6 | Lunch Sponsor |
| 7 | Beverage Sponsor |
+----+------------------+
I want to disable the select options in my form if the value of my select field matches the value in clay_plan_type
View example:
@if ($sponsortype === "Beverage Sponsor")
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
etc...
Controller Example:
$sponsortype = DB::table('clay_shoots')->select('clay_plan_type')->get();
return view('clayshoot.sponsorform',compact('sponsortype'));
When I dd($sponsortype);
I get the following:
Collection #855 ▼
#items: array:3 [▼
0 => #801 ▼
+"clay_plan_type": "Single Shooter"
1 => #802 ▼
+"clay_plan_type": "Lunch Sponsor"
2 => #803 ▼
+"clay_plan_type": "Beverage Sponsor"
]
I get no errors when running the if statement
in the view, but I don't get the correct results. It acts as the `if statement is not there.
So I try adding $sponsortype->clay_plan_type
and I get the error:
Property [clay_plan_type] does not exist on this collection instance.
If I run in a foreach loop
this works in the View but I get multiple repeats of the same item in the select field. (See below image)
@foreach($sponsortype as $st)
@if ($st->clay_plan_type == "Beverage Sponsor" )
YUP
@else
NOPE
@endif
@endforeach
// OUTPUT: NOPE NOPE YUP ("Beverage Sponsor" is the last record in the table)
Hope I'm explaining this in a way you understand. If you need more info, please let me know. Any help in figuring this out would be appreciated.
php laravel
$sponsortype
is a collection so you have to iterate over it in the@foreach
as you did on the last example. Everything seems to be working fine. You should put<input>
asYUP
andNOPE
and it will work. What is the problem here?
– Damian Dziaduch
Mar 25 at 14:21
I have 4 plans: Bev, Breakfast, Lunch and Singles. I'll have up to 24 Singles in thatclay_plan_type
column and when I loop it I'll end up getting 24 Bev, Breakfast and Lunch options in my select filed. That's my problem.
– echo
Mar 25 at 14:26
Not sure whether I understand. Can you show the content of theclay_plan_type
?
– Damian Dziaduch
Mar 25 at 14:33
@DamianDziaduch the content is whats in the database and the die dump.
– echo
Mar 25 at 14:44
@DamianDziaduch I added an image of the foreach loop on the Beverage Sponsor option filed to help show you my predicament.
– echo
Mar 25 at 14:49
add a comment |
What I'm needing:
Using the following DB column clay_plan_type
+----+------------------+
| id | clay_plan_type |
+----+------------------+
| 5 | Single Shooter |
| 6 | Lunch Sponsor |
| 7 | Beverage Sponsor |
+----+------------------+
I want to disable the select options in my form if the value of my select field matches the value in clay_plan_type
View example:
@if ($sponsortype === "Beverage Sponsor")
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
etc...
Controller Example:
$sponsortype = DB::table('clay_shoots')->select('clay_plan_type')->get();
return view('clayshoot.sponsorform',compact('sponsortype'));
When I dd($sponsortype);
I get the following:
Collection #855 ▼
#items: array:3 [▼
0 => #801 ▼
+"clay_plan_type": "Single Shooter"
1 => #802 ▼
+"clay_plan_type": "Lunch Sponsor"
2 => #803 ▼
+"clay_plan_type": "Beverage Sponsor"
]
I get no errors when running the if statement
in the view, but I don't get the correct results. It acts as the `if statement is not there.
So I try adding $sponsortype->clay_plan_type
and I get the error:
Property [clay_plan_type] does not exist on this collection instance.
If I run in a foreach loop
this works in the View but I get multiple repeats of the same item in the select field. (See below image)
@foreach($sponsortype as $st)
@if ($st->clay_plan_type == "Beverage Sponsor" )
YUP
@else
NOPE
@endif
@endforeach
// OUTPUT: NOPE NOPE YUP ("Beverage Sponsor" is the last record in the table)
Hope I'm explaining this in a way you understand. If you need more info, please let me know. Any help in figuring this out would be appreciated.
php laravel
What I'm needing:
Using the following DB column clay_plan_type
+----+------------------+
| id | clay_plan_type |
+----+------------------+
| 5 | Single Shooter |
| 6 | Lunch Sponsor |
| 7 | Beverage Sponsor |
+----+------------------+
I want to disable the select options in my form if the value of my select field matches the value in clay_plan_type
View example:
@if ($sponsortype === "Beverage Sponsor")
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
etc...
Controller Example:
$sponsortype = DB::table('clay_shoots')->select('clay_plan_type')->get();
return view('clayshoot.sponsorform',compact('sponsortype'));
When I dd($sponsortype);
I get the following:
Collection #855 ▼
#items: array:3 [▼
0 => #801 ▼
+"clay_plan_type": "Single Shooter"
1 => #802 ▼
+"clay_plan_type": "Lunch Sponsor"
2 => #803 ▼
+"clay_plan_type": "Beverage Sponsor"
]
I get no errors when running the if statement
in the view, but I don't get the correct results. It acts as the `if statement is not there.
So I try adding $sponsortype->clay_plan_type
and I get the error:
Property [clay_plan_type] does not exist on this collection instance.
If I run in a foreach loop
this works in the View but I get multiple repeats of the same item in the select field. (See below image)
@foreach($sponsortype as $st)
@if ($st->clay_plan_type == "Beverage Sponsor" )
YUP
@else
NOPE
@endif
@endforeach
// OUTPUT: NOPE NOPE YUP ("Beverage Sponsor" is the last record in the table)
Hope I'm explaining this in a way you understand. If you need more info, please let me know. Any help in figuring this out would be appreciated.
php laravel
php laravel
edited Mar 25 at 14:47
echo
asked Mar 25 at 14:16
echoecho
5578 silver badges26 bronze badges
5578 silver badges26 bronze badges
$sponsortype
is a collection so you have to iterate over it in the@foreach
as you did on the last example. Everything seems to be working fine. You should put<input>
asYUP
andNOPE
and it will work. What is the problem here?
– Damian Dziaduch
Mar 25 at 14:21
I have 4 plans: Bev, Breakfast, Lunch and Singles. I'll have up to 24 Singles in thatclay_plan_type
column and when I loop it I'll end up getting 24 Bev, Breakfast and Lunch options in my select filed. That's my problem.
– echo
Mar 25 at 14:26
Not sure whether I understand. Can you show the content of theclay_plan_type
?
– Damian Dziaduch
Mar 25 at 14:33
@DamianDziaduch the content is whats in the database and the die dump.
– echo
Mar 25 at 14:44
@DamianDziaduch I added an image of the foreach loop on the Beverage Sponsor option filed to help show you my predicament.
– echo
Mar 25 at 14:49
add a comment |
$sponsortype
is a collection so you have to iterate over it in the@foreach
as you did on the last example. Everything seems to be working fine. You should put<input>
asYUP
andNOPE
and it will work. What is the problem here?
– Damian Dziaduch
Mar 25 at 14:21
I have 4 plans: Bev, Breakfast, Lunch and Singles. I'll have up to 24 Singles in thatclay_plan_type
column and when I loop it I'll end up getting 24 Bev, Breakfast and Lunch options in my select filed. That's my problem.
– echo
Mar 25 at 14:26
Not sure whether I understand. Can you show the content of theclay_plan_type
?
– Damian Dziaduch
Mar 25 at 14:33
@DamianDziaduch the content is whats in the database and the die dump.
– echo
Mar 25 at 14:44
@DamianDziaduch I added an image of the foreach loop on the Beverage Sponsor option filed to help show you my predicament.
– echo
Mar 25 at 14:49
$sponsortype
is a collection so you have to iterate over it in the @foreach
as you did on the last example. Everything seems to be working fine. You should put <input>
as YUP
and NOPE
and it will work. What is the problem here?– Damian Dziaduch
Mar 25 at 14:21
$sponsortype
is a collection so you have to iterate over it in the @foreach
as you did on the last example. Everything seems to be working fine. You should put <input>
as YUP
and NOPE
and it will work. What is the problem here?– Damian Dziaduch
Mar 25 at 14:21
I have 4 plans: Bev, Breakfast, Lunch and Singles. I'll have up to 24 Singles in that
clay_plan_type
column and when I loop it I'll end up getting 24 Bev, Breakfast and Lunch options in my select filed. That's my problem.– echo
Mar 25 at 14:26
I have 4 plans: Bev, Breakfast, Lunch and Singles. I'll have up to 24 Singles in that
clay_plan_type
column and when I loop it I'll end up getting 24 Bev, Breakfast and Lunch options in my select filed. That's my problem.– echo
Mar 25 at 14:26
Not sure whether I understand. Can you show the content of the
clay_plan_type
?– Damian Dziaduch
Mar 25 at 14:33
Not sure whether I understand. Can you show the content of the
clay_plan_type
?– Damian Dziaduch
Mar 25 at 14:33
@DamianDziaduch the content is whats in the database and the die dump.
– echo
Mar 25 at 14:44
@DamianDziaduch the content is whats in the database and the die dump.
– echo
Mar 25 at 14:44
@DamianDziaduch I added an image of the foreach loop on the Beverage Sponsor option filed to help show you my predicament.
– echo
Mar 25 at 14:49
@DamianDziaduch I added an image of the foreach loop on the Beverage Sponsor option filed to help show you my predicament.
– echo
Mar 25 at 14:49
add a comment |
1 Answer
1
active
oldest
votes
You can use the contains
collection method and pass a key / value pair.
From the docs:
You may also pass a key / value pair to the contains method, which
will determine if the given pair exists in the collection:
$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
$collection->contains('product', 'Bookcase');
// false
In your case:
@if ($sponsortype->contains("clay_plan_type", "Beverage Sponsor"))
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
That worked perfect without aforeach loop
. Exactly what I was needing! Thanks!
– echo
Mar 25 at 14:57
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%2f55339860%2fget-value-from-select-field-and-compare-against-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the contains
collection method and pass a key / value pair.
From the docs:
You may also pass a key / value pair to the contains method, which
will determine if the given pair exists in the collection:
$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
$collection->contains('product', 'Bookcase');
// false
In your case:
@if ($sponsortype->contains("clay_plan_type", "Beverage Sponsor"))
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
That worked perfect without aforeach loop
. Exactly what I was needing! Thanks!
– echo
Mar 25 at 14:57
add a comment |
You can use the contains
collection method and pass a key / value pair.
From the docs:
You may also pass a key / value pair to the contains method, which
will determine if the given pair exists in the collection:
$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
$collection->contains('product', 'Bookcase');
// false
In your case:
@if ($sponsortype->contains("clay_plan_type", "Beverage Sponsor"))
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
That worked perfect without aforeach loop
. Exactly what I was needing! Thanks!
– echo
Mar 25 at 14:57
add a comment |
You can use the contains
collection method and pass a key / value pair.
From the docs:
You may also pass a key / value pair to the contains method, which
will determine if the given pair exists in the collection:
$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
$collection->contains('product', 'Bookcase');
// false
In your case:
@if ($sponsortype->contains("clay_plan_type", "Beverage Sponsor"))
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
You can use the contains
collection method and pass a key / value pair.
From the docs:
You may also pass a key / value pair to the contains method, which
will determine if the given pair exists in the collection:
$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
$collection->contains('product', 'Bookcase');
// false
In your case:
@if ($sponsortype->contains("clay_plan_type", "Beverage Sponsor"))
<option value="" disabled>Beverage Sponsor: SOLD OUT</option>
@else
<option value="Beverage Sponsor">Beverage Sponsor: $250</option>
@endif
edited Mar 25 at 15:00
answered Mar 25 at 14:51
RemulRemul
1,6951 gold badge4 silver badges14 bronze badges
1,6951 gold badge4 silver badges14 bronze badges
That worked perfect without aforeach loop
. Exactly what I was needing! Thanks!
– echo
Mar 25 at 14:57
add a comment |
That worked perfect without aforeach loop
. Exactly what I was needing! Thanks!
– echo
Mar 25 at 14:57
That worked perfect without a
foreach loop
. Exactly what I was needing! Thanks!– echo
Mar 25 at 14:57
That worked perfect without a
foreach loop
. Exactly what I was needing! Thanks!– echo
Mar 25 at 14:57
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55339860%2fget-value-from-select-field-and-compare-against-database%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
$sponsortype
is a collection so you have to iterate over it in the@foreach
as you did on the last example. Everything seems to be working fine. You should put<input>
asYUP
andNOPE
and it will work. What is the problem here?– Damian Dziaduch
Mar 25 at 14:21
I have 4 plans: Bev, Breakfast, Lunch and Singles. I'll have up to 24 Singles in that
clay_plan_type
column and when I loop it I'll end up getting 24 Bev, Breakfast and Lunch options in my select filed. That's my problem.– echo
Mar 25 at 14:26
Not sure whether I understand. Can you show the content of the
clay_plan_type
?– Damian Dziaduch
Mar 25 at 14:33
@DamianDziaduch the content is whats in the database and the die dump.
– echo
Mar 25 at 14:44
@DamianDziaduch I added an image of the foreach loop on the Beverage Sponsor option filed to help show you my predicament.
– echo
Mar 25 at 14:49