0

I changed the string in post.php in laravel (lang) directory, to change the language on the website

from

'search' => 'Search here...'

To

'search' => [
'placeholder' => 'Search here...',
'null' => 'Data not found'
],

after that an error occurs with the message

htmlspecialchars(): Argument #1 ($string) must be of type string, array given

if I restore it again everything works fine.

this is my blade.php

<input type="text" name="search" placeholder="{{ __('post.index.search.placeholder') }}">

blablabla

//for empty search request
<p>{{ __('post.index.search.null') }}</p>

help me!

Wildan Maulana
  • 62
  • 1
  • 1
  • 8

2 Answers2

2

Your post.php file in the lang directory should be like this. Whenever you are adding (.) in the __() function then make sure you have that properly structured in the language file. In your case, you have added post.index.search.placeholder, so you need to add a nested array in the language file.

return [
    'index'=> [
        'search' => [
            'placeholder' => 'Search here...',
            'null' => 'Data not found'
        ]
    ]
];

Check the screenshot

Output screenshot

0

Lang parameters only accept strings, therefore you should instead use:

<?php 

return 
[
  'search_placeholder' => 'Search here..',
  'search_empty' => 'Data not found',
];
Linesofcode
  • 5,327
  • 13
  • 62
  • 116