title: Laravel 5.8 Trying to query Arabic records from the database
body: <p>I'm trying to query some records in Arabic that I inserted earlier with the DB Facade with PDO. When I inserted those records the first time I noticed that everything inserted successfully but I can't see the Arabic text coming from the blade view file. So I checked the code and it was fine then I checked the database itself (Using TablePlus) and surprisingly found the Arabic text inserted successfully as well.</p>
  
  <p>Next, I went to check my database charset located in Config/Database.php and found it's set to utf8mb4 and the collation is utf8mb4_unicode_ci, So this means that Arabic shouldn't be an issue (I even tried to switch it to only utf8 but no luck).</p>
  
  <p>I went to check the query itself and I found that nothing is wrong, but as a courtesy, I thought I add "SET NAMES UTF8" before I execute my insert query and here is the weirdest thing... It showed the Arabic text when I redirected to the view after insertion. So I thought I only need to put "SET NAMES UTF8" before I select but when I did, it didn't show the Arabic text when I refreshed the view.</p>
  
  <p>Files:
  1 Controller:
  It has 2 actions, the first one is to query and pass the result to view and the other one is to insert then execute the same query to redirect to the view with the result.</p>
  
  <p>1 Blade View:
  Has a form to import the file that has the data and a table to show the result. The same blade view I use just to show the result if there are new files to insert.</p>
  
  <p>CODES:</p>
  
  <p>Code to insert data:</p>
  
  <pre><code>DB::table('workers')-&gt;insert($data);
  $pdo = DB::getPdo();
  $statement = $pdo-&gt;prepare("set names utf8");
  $statement = $pdo-&gt;prepare('select * from workers');
  $statement-&gt;setFetchMode(\PDO::FETCH_ASSOC);
  $statement-&gt;execute();
  $results = $statement-&gt;fetchAll();
  return view('payslips')-&gt;with('data', $results);
  </code></pre>
  
  <p>After executing this code I did <code>dd($results)</code> and I can see all data including Arabic text as well as the view shows everything.</p>
  
  <p>When I refresh the page which executes the following code:</p>
  
  <pre><code>$pdo = DB::getPdo();
  $statement = $pdo-&gt;prepare("set names utf8");
  $statement = $pdo-&gt;prepare('select * from workers');
  $statement-&gt;setFetchMode(\PDO::FETCH_ASSOC);
  $statement-&gt;execute();
  $results = $statement-&gt;fetchAll();
  return view('payslips')-&gt;with('data', $results);
  </code></pre>
  
  <p>The Arabic text disappears again. Even when I <code>dd($results)</code> I can't even see the Arabic text in the query result.</p>
  
  <p>In my blade view I use this format <code>{{ $data['name'] }}</code> to view records in table.</p>
  
  <p>I tried the previously mentioned steps and also tried adding UTF8 in my HTML and everywhere to make sure it's not the problem but nothing changed. I tried rendering Arabic text statically and it showed no problems at all.</p>
  
  <p>I also went to 
  <code>/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php</code> and injected the PDO initiation code with set names utf8 thinking it might fix the problem.</p>
  
  <pre><code>if (! empty($config['database'])) {
  $connection-&gt;exec("use `{$config['database']}`;");
  $connection-&gt;exec("set names utf8");
  }
  </code></pre>
  
  <p>To me, it seems like there is something I should do with the database query or configuration or something but I really don't know what is it. It's a very weird problem for me and I really need your professional solution guys, please.</p>