0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

エンコード Laravel

Last updated at Posted at 2025-12-13

エンコード

Laravelにおけるエンコードについて解説

文字コードの処理

  • Laravelでは特に何もしない場合、UTF-8を標準の文字コードとして使用
  • 基本的には文字化けを防ぐためにUTF-8に統一されている

データ形式のエンコード

  • PHPで扱っている連想配列やオブジェクトをJSON形式の文字列に変換

  • PHP関数

    • エンコード json_encode($array_or_object)
    • デコード json_decode($json_string)

使用例

  • Eloquentモデル
$user = App\Models\User::find(1);
return $user; // 自動的にJSON形式でレスポンスされる
  • コレクション
$users = App\Models\User::all();
$json_string = $users->toJson();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?