Acessing property from blade view laravel - laravel

Im trying to show some data in my view and ONLY the id property is getting changed to some random number when its passed to the view. The other properties are okay.
If I try to access a property from a view like this: {{ dd($var[1]) }}, it works and I can see the id like this:
But if I try to access passing the id directly: {{ dd($var[1]['id']) }} or {{ dd($var[1]->id) }}, I just get this:
And here are some more examples from what I get accessing it directly:
If I use gettype() is this var I get Integer back, but it is actually a string as you can see in the first printscreen.
Why is my blade view doing this? And how can I fix it?

I ended up using another id I was receiving in the same array, looks like blade was decoding the string or something like that. Thanks for the answers.

in your controller please select id as new_id and try to print
$var[1]->new_id or $var[1]['new_id']
it will fix your problem
if fixed give a green tick and a thumbs up else leave a commetn will try to update you

Related

Is it possible to manipulate the output of a laravel #yield in the blade template?

Wondering if it is possible to manipulate the output of a #yield in Laravel? In short I have a title in my child template that I would like to set some id's with to make them unique. I know I could just create another #section('id', 'asdf') but rather not have to worry users with that especially since the title has to be unique anyways...
Could not find anything that says this is possible?
Example (which fails) but what I am essentially trying to do:
id="{{Str::kebab(#yield('title'))}}-preview-tab"
#yield gets replaced with a PHP echo statement so that is not what you want. If you want the content of a section you can grab it from the View Factory:
$__env->getSection($name, $default)
Or even calling yieldContent:
$__env->yieldContent($section, $default)
So you could try:
{{ Str::kebab($__env->getSection('title', 'some default if you want')) }}
If you have any issues with that, try the yieldContent method.

Builder Plugin set identifier value through partial

I am trying to use output data that I have set up using the builder plugin through the Record Details component and running into some issues.
In my created plugin, Schools, I have Instructors (set up as a relation to an instructors plugin I created separately). It is possible to have more than one instructor, so they are store in the database as an array. Like so:
[{"instructor":"69"},{"instructor":"79"},{"instructor":"80"},{"instructor":"96"}]
The numbers represent the row ID of the instructor table
In my CMS I can pull all of the School info just fine into a partial (Builder Details), and can pull the array of instructors, but I am struggling to pass this array over to look up the ID and get the instructors information. My thought right now is to send it to another partial like so:
{% "school/instructor" insProfile = instructorID %}
The partial school/instructor is getting the ID just fine. I have included the Builder Details component and set it up with the following:
Alias: builderDetails
ModelClass: Instructors Plugin
Identifier value: insProfile
Key Column: id
Display Column: member_name
I am getting record not found results. I am confused as to how to set the Identifier Value to match the value I passed through my partial. I tried {% set identifierValue = insProfile %} before the {% set record = ... %} is run, but that did not work either.
I cannot use the :slug because that is already generating the content needed for the School page. In a TLDR, it seems I ultimately want to duplicate this function through another partial and a different tag.
Still learning October, so any help is appreciated.
I think the original post was a bit lengthy and ultimately what I wanted to do was pass a variable into a component. Such as:
{% component 'builderDetails' identifierValue=dynamicVar %}
This does not appear to work as the builder details component generates too far into page load to pick up the variable change.
Per the OctoberCMS docs, the best solution for me was to create my own component that would accept the variable before the page processed using onRender() function.
public function onRender()
{
// This code will be executed before the default component
// markup is rendered on the page or layout.
$this->profileID = $this->property('insProfile');
$this->ins = $this->getUserInfo($this->profileID);
}
This allows me to put my component in a partial, and request the partial with the variable 'insProfile'. The component will pick up the property insProfile before page/plugin generates and use that variable instead of the default.
I then set up another function to query the correct user info needed (getUserInfo)
It would be nice if the builder plugin components could be updated in such a way that I did not have to do this as the builder plugin is rather extensive out of the box.
Posting this in case anyone else comes along this problem and isn't sure where/how to pass a partial variable into a component.

How to get a specific value from vue.js asp.net-core-mvc result set

I've made an implementation of vue.js in an .net-core mvc project which will return data from a controller. So let's say that the result is:
[{"id":1,"uniqueStr":"string1","ttlValue":"something","hlpValue":"something2"},{"id":2,"uniqueStr":"string2","ttlValue":"something","hlpValue":"something2"}]
I can get the row value with a snippet like:
{{ data[0] }}
So I have two things remaining. The situation is, I need the rows on one page without a loop. So my question would be:
How can I get the "ttlValue" of the row where the "uniqueStr" would be "string2".
I thinking something in the line of but that obviously doesn't function:
{{ data[0][1] }}
I would do it with a computed value, like this. If you need to pass a parameter, you can use a method instead, like this.
I'm not sure what you meant with without a loop though. My solution loops through the object with .filter and with your current data structure, it's not really doable more directly.

Laravel 4 Former::checkbox() always checked

I'm having an issue with the Laravel 4 Package Former and the use of checkboxes. I'm trying to Former::populate() a user edit form within a blade template but my checkboxes are always checked.
Here is my current code:
{{ Former::checkbox('is_admin')->text('Is Admin?'); }}
I've tried:
{{ Former::checkbox('is_admin')->text('Is Admin?')->check(false); }}
and
{{ Former::checkbox('is_admin')->text('Is Admin?')->forceValue(false); }}
To no avail.
My database field 'is_admin' is a boolean field. I thought maybe Former didn't like 1s and 0s but it doesn't uncheck my checkboxes even if I set a getter to return false.
Any Ideas?
Thanks
Sounds like a bug with Former.. Keep in mind it looks like you can overrule whatever happened with populate with populateField.

Magento: how do I access custom variables in PHP?

I am aware of 'Custom Variables' and how they can be used with {{ }} brackets in email templates as well as in static blocks.
However, I want to use them in template code i.e. view.phtml.
I want to be able to access 'variable plain value' to retrieve a conversion value, i.e. a number/string as number for a given 'variable code'.
Been doing this for some time to create various messages that are editable through the admin interface so I don't have to go code digging when the flavor of the moment changes.
To access the plain value of the custom variable with code custom_variable_code use this:
Mage::getModel('core/variable')->loadByCode('custom_variable_code')->getValue('plain');
NOTE: Single store doesn't show the store select dropdown for the variable scope. This answer is not technically correct, in order to future-proof yourself in case of having multiple stores --> Please see #Mark van der Sanden answer below and give him an upvote.
Unfortunately, all other answers are not 100% correct. Use it like this (note the setStoreId() to get the value for the correct store view):
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('text');
Or to get the html value:
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('html');
If no html value is defined, getValue() returns the text value if you request the html value.
Stackoverflow almost to the rescue again. Thought this would be it:
Setting a global variable in Magento, the GUI way?
But it wasn't, this was:
$angle = Mage::getModel('core/variable')->loadByCode('angle')->getData('store_plain_value');
The only way I see you can acheive this by having a method in the templates block, that will output the needed result.
For instance say in the template view.phtml you have the following code:
<div id="title_container">
<h2><?= $this->getTitle(); ?></h2>
</div>
The function can represent your variable code and any logic that has to do with what gets displayed in the title should be placed in the block.
Just for clarification sake the block is the variable $this
If you are unsure what is the actual class name of your block you can do something like:
Mage::log(get_class($this));
in the var/log/system.log you will print the class of the block of that template.
That is the best way.
HTH :)
// To get the TEXT value of the custom variable:
Mage::getModel('core/variable')->setStoreId(Mage::app()->getStore()->getId())->loadByCode('custom_variable_code')->getValue('text');
// To get the HTML value of the custom variable:
Mage::getModel('core/variable')->setStoreId(Mage::app()->getStore()->getId())->loadByCode('custom_variable_code')->getValue('html');
// The store id is set as Custom Variables can be edited for multiple stores
Note: A custom variable might have different values for different stores.
So to access store specific value for the custom variable with the code custom_variable_code
Use this:
$storeId = Mage::app()->getStore()->getId();
$custom_variable_text = Mage::getModel('core/variable')->setStoreId($storeId)
->loadByCode('custom_variable_code')
->getValue('text');
$custom_variable_plain_value = Mage::getModel('core/variable')->setStoreId($storeId)
->loadByCode('custom_variable_code')
->getValue('plain');
$custom_variable_html_value = Mage::getModel('core/variable')->setStoreId($storeId)
->loadByCode('custom_variable_code')
->getValue('html');

Resources