Aydın Bulut
Aydın Bulut

Reputation: 132

Laravel 5 Turkish Character Issue

I am new in Laravel and am trying to get in by developing a website. I have my onw cms for corporate websites and am using it. I have created a model to get data from database that added from ckeditor. But somehow i am facing turkish character issue. If some one can help me it would be very good for a new laravel developer :)

My database configuration:

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

My SingleContent Model

namespace App\Model\Modules;

use App\Model\Config\Language;
use App\Model\Config\Menulist;
use Illuminate\Database\Eloquent\Model;

class SingleContent extends Model
{

/**
 * The table associated with the model.
 *
 * @var string
 */
public $table = "resimsiztekicerik";

/*
 * Set increment column name
 *
 * @var string
 */
protected $primaryKey = "entryId";

/**
 * Indicates if the model should be timestamped.
 *
 * @var bool
 */
public $timestamps = false;

// MASS ASSIGNMENT -------------------------------------------------------
// define which attributes are mass assignable (for security)
// we only want these 1 attributes able to be filled
protected $fillable = array('entryTitle','entryContent');


/*
 * get content of given menu id
 *
 * @param int
 *
 * @return array (database record row)
 */
public static function getContent($menuId)
{

    return SingleContent::where('langId',1)->where('menuId',1)->first();
}

}

My AppController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App;
use App\Model\Config\Language;
use App\Model\Config\Menulist;
use App\Model\Modules\SingleContent;

class AppController extends Controller
{

public function index()
{

    // about me content
    $about_me = SingleContent::getContent(1);

    // view datas
    $view_data = array();
    $view_data['about_me'] = $about_me;

    return view('app',$view_data);
}

}

My app.blade

...
<meta charset="utf-8">
...
<div class="block">

  <div class="block-title">
    {{ $about_me->entryTitle }}
  </div>
  <div class="block-content">
    {!! $about_me->entryContent !!}
  </div>

</div>
...

Result For {{ $about_me->entryTitle }}:

Hakkımda

Result For {!! $about_me->entryContent !!}:

Web ProgramcılıÄı ile lisede tanıÅtım ve yapmam gereken mesleÄin bu  olduÄuna inanarak 1 yıllık stajımı tamamladıktan sonra 6 yıldır web geliÅtirme alanında profesyonel olarka hizmet veriyorum. Kurumsal websitesi, e-ticaret websitesi, otomasyon, vb. alanlarında çalıÅmalarım oldu.

EDIT:

By the way, this ow my record looks like in phpmyadmin and i am using utf8_geneal_ci in columns, tables and database settings as well, its lookf fine in my cms and codeigniter, but I am not sure if it is correct. I have lack of experience about encoding.

enter image description here

Upvotes: 1

Views: 1892

Answers (2)

Aydın Bulut
Aydın Bulut

Reputation: 132

I solved it by converting database, tables, and columns collation

from

utf8_general_ci

to

utf8mb4_unicode_ci

Upvotes: 1

Maraboc
Maraboc

Reputation: 11093

Try to add Blade::setEchoFormat('e(utf8_encode(%s))'); in the boot method of your AppServiceProvider

Upvotes: 1

Related Questions