我正在尝试从数据库设置slack api工作区令牌。
slackMiddleware.php
public function handle($request, Closure $next, $guard = null)
{
if (session()->has('slack_token')){
config(['services.slack.token' => session('slack_token')]);
}
else
{
$setting = SlackSetting::whereUserId(auth()->id())->first();
if ($setting){
session(['slack_token' => $setting->token]);
config(['services.slack.token' => session('slack_token')]);
}
}
return $next($request);
}
当我试图访问索引页api时,调用成功返回数据。但当另一页访问。从slack api调用返回无效的auth错误。
主layout.blade.php
@inject('channelRepo', "Modules\Slack\Repositories\SlackChannelRepo")
@php
$channels = $channelRepo->fetchAll()->channels;
@endphp
@extends('layouts.admin')
section('content')
@parent
@include('slack::includes.workspace-selection')
<div class="row">
<div class="col-md-3">
@include('slack::includes.side-bar-left', compact('channels'))
</div>
<div class="col-md-9">
@include('slack::includes.header')
@yield('slack-content')
</div>
</div>
@stop
每次从config调用时都会收到令牌。数据仅在索引页面调用时返回。
SlackChannelRepo.php
public function fetchAll(array $params = [])
{
//dd(config('services.slack.token'));
$channels = $this->all();
//dd($channels);
return $channels;
}
index.blade.php
@extends('slack::layouts.slack-master')
@section('title', 'Slack')
@section('slack-content')
<h1>Hi Slack</h1>
endsection
@push('stylesheet')
@endpush
@push('scripts')
@endpush