Laravel view not displaying long number correctly - laravel-4

I have a column name xxx in database. it is of type varchar(255). It is storing 9006686769394. I access its value and store it in a variable named $refCode. When I do {{ $refCode }} in laravel view, it displays like this: 9.00668676939E+12. Why can't I display the variable properly ? Any suggestion ?

Related

Laravel 9 Won't count all users from database table error

Alright so, I've been trying to make it so on the main page (main.blade.php) theres a text saying that there's (this) many users registered. I did the code which is {{ count(Schema::getColumnListing('users')); }} but it's only counting 9 users even though I got 23 users registered.
getColumnListing() returns the columns of the table. You should use count() on a Laravel model instead.
You already have a user model, from the base Laravel project. Using that, this will suffice.
{{ User::count(); }}
The getColumnListing('users') is not what you think it is. You might want to count rows here since you are talking about number of users.
Schema::getColumnListing('users') will return the columns of table i.e., id, username, password etc, do this instead:
User::count() // this will return the total number of rows

Retrieving a single value from belongsToMany relationship in blade template

I have created a model with a belongsToMany relationship. The model is Vendor and the relationship with Location. So, in my blade template, I would normally do something like this:
#foreach ($vendor->locations as $loc)
{{$loc-id}}
#endforeach
However, I would like to simply json_encode only the id values for each of the locations. If possible, I would like to do so without creating a loop. So, I know I can do this:
{{json_encode($vendor->locations)}}
But as you can guess, this dumps out JSON data of all of the fields in the locations table.
I know I can modify my relationship to only include the ID fields, but I do not want to do this because I want to use the relationship elsewhere.
Is there a way to just grab the ID fields using something like:
{{json_encode($vendor->locations->id)}}
You can pluck the 'id' and convert it directly to json.
{{ $vendor->locations->pluck('id')->toJson() }}
This requires that $vendor->locations is a Collection.
You can use Laravel's pluck and json methods:
{{ $vendor->locations->pluck('id')->toJson() }}
You can refer to the documentation for more information:
https://laravel.com/docs/8.x/collections#method-tojson

Laravel blade template name from database

I have a master blade file which will include another blade file based on a DB value like so:
#include('sign/templates/{{$SignRequest->form_template}}')
The db field form_template contains the name of the blade file to include. This name is passed to the master blade file correctly, but I can't figure out how to use this value within the include statement.
I get the following error:
View [sign.templates.<?php echo e($SignRequest->form_template); ?>] not found.
#include('sign.templates.'.$SignRequest->form_template)

Servicenow - Service Catalog Reference Field - Insert different column than the display value

Let me describe my problem:
I have a table for all my IT-Services. I reference to this table more than once, for different purposes. Most of the time I need to reference to the name of the service. That's why I keep the name as displayed value.
One Column of that table is a service_id (custom field) which is for example "Service_004". Now in a catalog request Item the User has to fill in the service_id in a reference field.
But since I have the name as displayed value, and I need it in other forms, I am unable to reference to the service_id.
Using the variable attributes field I managed to let the service be found using the autocomplete function. But in the reference field I still get the servicename. I know that I can change the display value in the dictionary, but this breaks other functions. So what I need is to change the display value just for one reference field.
Also I tried to create a new table called IT-Services2 with reference to my table IT-Services. Then I switched the display to true in the new table for my service_id, but this will even change it in the parent table.
Perhaps an onChange client script utilizing g_form.setLabelOf() ?
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#setLabelOf
Maybe I'm not fully understanding your question...
I ran into this issue before, what you can do is create select box variable and use an on load client script to populate the list with the service_id(s) from the table you are referencing.
I would write a script include to pull the data from the table and call it from the client script via GlideAjax.

Spring : Updating table entry

I am new to Web applications. I am implementing a simple one that enables to show all the entries of a table (i am using Spring + Hibernate). I added a column that contains a link enabling the update of a table entry (in reality, juste one column can be updated the other ones shouldn't be changed).
I would like that when i click on this update link, a form of update should be displayed
and this form is initialised with the values of the columns of the table entry.
for example: if the entry is :
USER1 | 55 | 190cm | 80kg | "update link"
only the weight column can be updated, so the form of update so be initialised with:
name : USER1 (cannot be changed)
age : 55 (cannot be changed)
height : 190cm (cannot be changed)
weight : 80kg ( THE ONLY COLUMN THAT CAN BE CHANGED)
How can i pass the values from the "display.jsp" page to the "update.jsp" page?
should i pass through the controller or froma jsp to jsp directly?
Thanks,
Each controller must be responsible for loading appropriate data and passing them to corresponding view. The only info that you need to pass from one page to another is unique identifier of choosen line. Consider example where you want to change a record with unique identifier = 758. Normally unique identifier will be passed trough URL param:
http://example.com/update_controller_address?id=758

Resources