teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

Userモデルのコードを記載

2020/09/29 12:11

投稿

uesugi11
uesugi11

スコア6

title CHANGED
File without changes
body CHANGED
@@ -107,7 +107,63 @@
107
107
  }
108
108
 
109
109
  ```
110
+ app\User.php
111
+ ```ここに言語を入力
112
+ <?php
110
113
 
114
+ namespace App;
115
+
116
+ use Illuminate\Contracts\Auth\MustVerifyEmail;
117
+ use Illuminate\Foundation\Auth\User as Authenticatable;
118
+ use Illuminate\Notifications\Notifiable;
119
+
120
+ class User extends Authenticatable
121
+ {
122
+ use Notifiable;
123
+ /**
124
+ * The attributes that are mass assignable.
125
+ *
126
+ * @var array
127
+ */
128
+ protected $fillable = [
129
+ 'name', 'email', 'password',
130
+ ];
131
+
132
+ /**
133
+ * The attributes that should be hidden for arrays.
134
+ *
135
+ * @var array
136
+ */
137
+ protected $hidden = [
138
+ 'password', 'remember_token',
139
+ ];
140
+
141
+ /**
142
+ * The attributes that should be cast to native types.
143
+ *
144
+ * @var array
145
+ */
146
+ protected $casts = [
147
+ 'email_verified_at' => 'datetime',
148
+ ];
149
+
150
+ public function responses(){
151
+ return $this->belongsToMany('App\Response', 'response_user', 'user_id', 'response_id');
152
+ }
153
+ public function questionnaireUsers(){
154
+ return $this->hasMany('App\QuestionnaireUser');
155
+ }
156
+ public function questionnaires(){
157
+ return $this->hasManyThrough('App\Questionnaire', 'App\QuestionnaireUser', 'user_id', 'id', 'id', 'questionnaire_id' );
158
+ }
159
+ public function answers(){
160
+ return $this->hasManyThrough('App\Answer', 'App\Response', 'answer_id', 'id', 'id', 'answer_id');
161
+ }
162
+
163
+ }
164
+
165
+ ```
166
+
111
167
  ### 試したこと
112
168
 
113
169
  自分ではどのように検索すればいいのかわからず、こちらに投稿させて頂きました。

1

Unicodeエスケープを無効化するためのmiddlewareのコードを記載しました

2020/09/29 12:11

投稿

uesugi11
uesugi11

スコア6

title CHANGED
File without changes
body CHANGED
@@ -27,6 +27,8 @@
27
27
  public function __construct()
28
28
  {
29
29
  $this->middleware('auth');
30
+ $this->middleware('UnescapeJsonResponse');
31
+
30
32
  }
31
33
 
32
34
  /**
@@ -70,11 +72,50 @@
70
72
  @endsection
71
73
 
72
74
  ```
75
+ Http\Middleware\UnescapeJsonResponse.php
76
+ ```ここに言語を入力
77
+ <?php
73
78
 
79
+ namespace App\Http\Middleware;
80
+
81
+ use Closure;
82
+ use Symfony\Component\HttpFoundation\JsonResponse;
83
+
84
+ class UnescapeJsonResponse
85
+ {
86
+ /**
87
+ * Handle an incoming request.
88
+ *
89
+ * @param \Illuminate\Http\Request $request
90
+ * @param \Closure $next
91
+ * @return mixed
92
+ */
93
+ public function handle($request, Closure $next)
94
+ {
95
+ $response = $next($request);
96
+
97
+ //JSONでない場合はそのまま
98
+ if (!$response instanceof JsonResponse) {
99
+ return $response;
100
+ }
101
+
102
+ // Unicodeエスケープさせないようにオプションを追加
103
+ $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
104
+
105
+ return $response;
106
+ }
107
+ }
108
+
109
+ ```
110
+
74
111
  ### 試したこと
75
112
 
76
113
  自分ではどのように検索すればいいのかわからず、こちらに投稿させて頂きました。
77
114
 
115
+ ※追加
116
+ [Unicodeエスケープを無効化](https://nextat.co.jp/staff/archives/203)
117
+ こちらの記事を参考にUnicodeエスケープを無効化を試みたのですが、うまくいかない状況にあります。
118
+
78
119
  ### 補足情報(FW/ツールのバージョンなど)
79
120
 
80
121
  php -v