Good evening guys, I am having a rather strange problem here. I cannot find any resource online either regarding what is happening.
When I display information in my blade template using the following in my controller:
$results = DB::table('datatest') -> get();
if ($results != null) {
return view('userview') -> with ('name', $results);
}
It capitalizes every word passed into my blade template. So let's say I pass an entire paragraph from my database, every first letter from each word in my paragraph becomes capitalized.
Here is a cutout from my view:
@foreach ($name as $name)
<tr>
<td>
{!!Form::label($name -> Author)!!}
</td>
<td>
{!!Form::label($name -> Title)!!}
</td>
<td>
{!!Form::label($name -> Year)!!}
</td>
<td>
{!!Form::label($name -> Abstracts)!!}
</td>
</tr>
@endforeach
//
On the other hand, when I choose to pass information to my other template with the following:
$data = DB::table('datatest')->where('id', $id)->first();
$Author = $data -> Author;
$Title = $data -> Title;
$Year = $data -> Year;
$Abstracts = $data -> Abstracts;
$results = array('AUTHOR' => $Author, 'TITLE' => $Title, 'YEAR' => $Year, 'ABSTRACTS' => $Abstracts);
return view('userview2') -> with ($results);
This is able to pass data into my Blade Template that does not alter the capitalization of the words in any way:
</tr>
<td>{!!Form::label('title', $TITLE)!!}</td>
<td>{!!Form::label('author', $AUTHOR)!!}</td>
<td>{!!Form::label('year', $YEAR)!!}</td>
<td>{!!Form::label('abstracts', $ABSTRACTS)!!}</td>
</tr>
Has anyone also encountered this problem? If so, can anyone explain the reason behind this?
Thanks in advance!
One of blade directive @stack('scripts') is very helpful when you have javascript need to execute in the child page. I create a fresh Laravel installation to demo an example. I have to make auth scaffolding with laravel/ui package because I'm using Laravel 6.
“capitalize string in php laravel” Code Answer's$bar = ucwords($bar); // HELLO WORLD! $bar = ucwords(strtolower($bar)); // Hello World! $bar = ucwords($foo); // Hello|world!
Laravel Blade template engine enables the developer to produce HTML based sleek designs and themes. All views in Laravel are usually built in the blade template. Blade engine is fast in rendering views because it caches the view until they are modified. All the files in resources/views have the extension .
Two of the primary benefits of using Blade are template inheritance and sections. We can define a blade page as a combination of layout and sections. Since most of the general web applications will have the same layout across the web pages.
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>
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With