私はLaracastのAPIチュートリアルに従い、他のすべてのコントローラーが拡張するApiController
を作成しようとしています。応答処理はApiController
が担当します。Laravel 5.4:クラス 'App Http Controllers Response'が見つかりませんでした
class ApiController extends Controller
{
protected $statusCode;
public function getStatusCode()
{
return $this->statusCode;
}
public function setStatusCode($statusCode)
{
$this->statusCode = $statusCode;
}
public function respondNotFound($message = 'Not Found!')
{
return Reponse::json([
'error' => [
'message' => $message,
'status_code' => $this->getStatusCode()
]
]);
}
}
私もApiController
を拡張ReportController
を持っています。
class ReportController extends ApiController
{
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$report = Report::find($id);
if (! $report) {
$this->respondNotFound(Report does not exist.');
}
return Response::json([
'data'=> $this->ReportTransformer->transform($report)
], 200);
}
}
私はReportController
からrespondNotFound
メソッドを呼び出そうとするとき、私は私が親またはにuse Illuminate\Support\Facades\Response;
を追加本家
見つからないエラー
クラスのレスポンス\アプリケーション\のHttp \コントローラ」を取得子クラス私はエラーを取得します。どうすればこの問題を解決できますか?
ご協力いただければ幸いです。
はレスポンスを使用し 'てみてください。'代わりに。または、 'response()'ヘルパー - 'return response() - > json(...);'です。 – ceejayoz
クラス 'Response'をインポートするために使用している名前空間が正しくないようです。正しいものを使用してください。 – Mojtaba
Useステートメントはファイルごとですが、それらが親クラスに含まれていても子クラスに含める必要があります。子クラスにfacade use文を追加するか、 '\ Response'を使用する – jfadich