如何在Laravel中响应403传递消息?

时间:2017-09-15 07:46:35

标签: php laravel

我正在尝试向Laravel中的自定义403页面显示自定义消息。但是没有显示消息,我不知道为什么不。

在laravel网站上,他们表明了这一点:

return response()->view('hello', $data, 200);

在我的项目控制器中,我这样做:

return response()->view('errors.403', array('message' => 'Sellist kasutajatüüpi ei eksisteeri!'), 403);

在我看来,我有这个:

    @if(Session::has('message'))
    <p class="error-page-text">{{ Session::get('message') }}</p>
    @else
    <p class="error-page-text">You don't have access to this page.</p>
    @endif

但是没有显示自定义错误消息。我该如何展示呢?

1 个答案:

答案 0 :(得分:3)

您将其作为变量传递,而不是在会话中传递

import {NgModule} from '@angular/core';
import {ConnectionBackend, RequestOptions} from '@angular/http';

import CancellationAwareHttpClient from 'app/services/cancellation-aware-http-client';

let cancellationAwareClient: CancellationAwareHttpClient;

const httpProvider = {
  provide: Http,
  deps: [ConnectionBackend, RequestOptions],
  useFactory: function (backend: ConnectionBackend, defaultOptions: RequestOptions) {
    if (!cancellationAwareClient) {
      const wrapped = new Http(backend, defaultOptions);
      cancellationAwareClient = new CancellationAwareHttpClient(wrappedHttp);
    }
    return cancellationAwareClient;
  }
};

@NgModule({
  providers: [
    // provide our service as `Http`, replacing the stock provider
    httpProvider,
    // provide the same instance of our service as `CancellationAwareHttpClient`
    // for those wanting access to `cancelOutstandingRequests`
    {...httpProvider, provide: CancellationAwareHttpClient}
  ]
}) export class SomeModule {}