I'm using laravel 9. I have stored data using summer note in the database, but it shows empty or null when I retrieve data from the database.
here is my code.
{!! Str::of($item->product_description)->limit(40) !!}
Try this
{!! Str::limit($item->product_description,40) !!}
Related
I am running a Laravel app on heroku and built a multi step form, that updates the object on every step. I also make use of the HTML library, which assists me in creating the forms, see my code below. Now I realized, that the model binding for selects is not working, when I open the form later. Instead, the first option of the array of options is displayed as default.
However, this only happens on production environment (heroku) and not on my local xampp server. Furthermore, model binding works in production on numbers or strings, only selects don't bind correctly.
I also tested, that the object has the correct value so it's not a database saving error and everything works fine.
Review my code below:
// Form is opened here
{!! Form::model($umzug, ['method'=>'PUT', 'action' => array('UmzugController#update', $umzug->id)]) !!}
...
<div class="col-sm-6">
{!! Form::label('halteverbot_auszug', 'Halteverbot') !!}
// Following line prints 'N', as it was selected previously and was therefore saved correctly in the DB
{{ $umzug->halteverbot_auszug }}
// Following line should produce a select input with 'Nein' selected, but shown 'Ja' instead
{!! Form::select('halteverbot_auszug', ['J' => 'Ja', 'N' => 'Nein'], null, ['class'=>'form-control', 'id'=>'halteverbot_auszug']) !!}
</div>
...
{!! Form::close() !!}
As the code is the same in production and on local, I have no clue how it can produce different outcomes, but I would be glad to hear any suggestions on how I can fix it.
Thanks in advance!
I was able to resolve the issue, by using 0 and 1 instead of 'J' and 'N'. I assume, that the different database types (mysql locally and postgresql on heroku) are handling characters different and second not as well as the first. Using integers instead fixed my problem.
I just started to use Laravel Collective. However, I encounter a problem when I try to extract the value from the Select Form.
{!! Form::open(['method'=>'POST','action'=>['ExpenseController#store'],'files' =>false], array('enctype'=>'multipart/form-data','id'=>'customer_contact','class' => 'form-validate1')) !!}
{{ Form::select('account_categories', $account_name,null, array("class"=>"dropdown-toggle form-control",'placeholder'=>'Please select ...')) }}
{!! Form::close() !!}
And it will look like this
But when I try to get the value from this select form via $request and return back to the Laravel, it output number instead of string value selected by user like this:
"account_categories":"5"
How can I get the string value selected by users from this SELECTBOX FORM ?
I have a variable $title that I want to save in the database.
I need to display it with its value on the page using Laravel5.
my code is:
{!! $article->title !!}
that gives me the following data on the page : $title , instead I want to see the value of the variable.
I will appreciate any help.
to output it on blade:
{{ $article->title }}
Are you sure that you have the right value in the database? Because {!! $article->title !!} don't make much more than convert it into
<?php echo $article->title ?>
so if you get $title as output, my assumption is that you store that in some way as value to the db.
you also can execute normal php in blade, so try to
<?php var_dump($article)?>
or
<?php var_dump($article->title)?>
to check what you really receive.
Output in laravel 5 blade:
{{ $article->title }}
Is there some way to insert a blank option when creating a select input with the Laravel FormBuilder? I have this at the moment but I want to change it
{!! Form::select('tipo_id', ['blank' => ''] + $tipos, null, ['class' => 'form-control']) !!}
You cannot do too much better than you are already doing. Secret is to have array first element empty to show blank input.
In Laravel 5 and Blade, I'm using a form with a textarea to store text in a mysql database and then display it back out to the user. I want to be able to preserve the carriage returns. I tried the simple approach of using the nl2br()
function which replaces the \r\n with tags:
public function setBodyAttribute($data){
$this->attributes['body'] = nl2br($data);
}
It seems that Blade won't allow html to be displayed as HTML.
{{ $example->body }}
What is the best way to get around this?
Since you mentioned Laravel 5, you're looking for:
{!! $example->body !!}
In Laravel 4, {{ $data }} would echo data as is, whereas {{{ $data }}} would echo data after running it through htmlentities.
However, Laravel 5 has changed it so that {{ $data }} will echo data after running it through htmlentities, and the new syntax {!! $data !!} will echo data as is.
Documentation here.