How to Capitalize First Letter in Laravel Blade

How to capitalize first letter in Laravel Blade

Use PHP's native ucfirst function:

{{ ucfirst(trans('messages.welcome')) }}

Capitalized a blade's variable in Laravel

Only first character :

You could use UCFirst, a PHP function

{{ucfirst(trans('text.blabla'))}}

For the doc : http://php.net/manual/en/function.ucfirst.php


Whole word

Str::upper($value)

Also this page might have handy things : http://cheats.jesse-obrien.ca/

Make First Letter of an Array Uppercase in Laravel

ucfirst(strtolower($main[0]->property)) is what you want to do.

$main is an array of objects because you're using ->get();

If you were fetching just one with ->first(); it would return an eloquent object and you would simply call ucfirst(strtolower($main->property))

If you have more than one result you could simply loop over or use fancy array functions builtin to php.

If it is an eloquent collection they have built in methods such as ->each() that allow you to map an array.

Capitalize first letter in form input - Laravel

You can use the function ucfirst from PHP

For example

{{ ucfirst(trans('messages.yourMessage')) }}

Making first letter uppercase in Laravel breadcrumbs

You can make it with ucfirst very easily

<ul class="breadcrumb">
<li>
<i class="glyphicon glyphicon-home"></i>
<a href="{{ URL::to('/') }}">Home</a> /
@for($i = 0; $i <= count(Request::segments()); $i++)
<a href="">{{ucfirst(Request::segment($i))}}</a>
@if($i < count(Request::segments()) & $i > 0)
/
@endif
</li>
@endfor
</ul>

Laravel words passed to Blade somehow become capitalized without explanation

That's just how Form::label works. According to the documentation, if you want to get untouched output, you should use labels with two parameters like this:

{!! Form::label('email', 'e-mail address') !!}

Which outputs:

<label for="email">e-mail address</label>

In your first cutout you're passing just one parameter and Form::Label prettyfies this string, so:

{!! Form::label('my email'); !!}

Becomes this:

<label for="my email">My Email</label>

How it works

Label builder checks second parameter and if it doesn't exist or it's null, builder passes label $name to the formatLabel() method which uses ucwords() to capitalize every word's first character.

protected function formatLabel($name, $value)
{
return $value ?: ucwords(str_replace('_', ' ', $name));
}

Get first letter of word in statement

If you are using MySQL 8+, then a raw select with REGEXP_REPLACE should work here:

$users = DB::table('animals')
->select(DB::raw("SELECT REGEXP_REPLACE(name, '(\\w)\\w+\\s*', '$1')"))
->get();

How to capitalize a word that has all letters in as capital letters in css OR php

A php solution would be to convert case to lower and then use ucfirst

$text = 'THIS IS A TITLE';
$normalText = ucfirst(strtolower($text));
echo $normalText;

PHP Laravel Convert array value to upper case

If you're getting data from DB by using Eloquent, you could create an accessor

public function getProvince($value)
{
return strtoupper($value);
}

If not, you could change it manually:

for ($i = 0; $i < count($data); $i++) {
$data[$i]['province'] = strtoupper($data[$i]['province']);
}


Related Topics



Leave a reply



Submit