Array
(
    [0] => Array
        (
            [answer_id] => 255014
            [ask_id] => 171438
            [uid] => 1271571
            [nickname] => P粉978551081
            [content] => <?xml encoding="utf-8" ?><html><body><p><strong>是的,可以</strong>。並且您需要執行以下操作-</p>
<ol>
<li><strong>只有透過中間件才能動態變更會話生命週期</strong>。因為透過任何控制器<strong>(沒有中間件)更改它都不會更改會話值</strong>,因為會話已經啟動。所以你需要一個中間件。就像下面這樣-</li>
</ol>
<pre class="brush:php;toolbar:false;">namespace App\Http\Middleware;

class ChangeSessionValueDynamically
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, $next)
    {
        $lifetime = 1440; /* Minutes*/
        config(['session.lifetime' => $lifetime]); /* Helper function */
        return $next($request);
    }
}</pre>
<ol start="2">
<li>之後,您需要將該中間件新增至 app/Http/Kernel.php 檔案中的 $middlewarePriority 陣列中,該檔案必須在 Laravel 執行自己的「StartSession」中間件之前執行。就像下面這樣-</li>
</ol>
<p>在 <code>\Illuminate\Session\Middleware\StartSession::class,</code> 之前加入 <code>\App\Http\Middleware\ChangeSessionValueDynamically::class,</code>。 </p>
<pre class="brush:php;toolbar:false;">/**
     * The priority-sorted list of middleware.
     *
     * This forces non-global middleware to always be in the given order.
     *
     * @var array
     */
    protected $middlewarePriority = [
     ....
     ....
        \App\Http\Middleware\ChangeSessionValueDynamically::class
        \Illuminate\Session\Middleware\StartSession::class,
     ....
     ....   
    ];</pre>
<ol start="3">
<li>提供 <code>\App\Http\Middleware\ChangeSessionValueDynamically::class</code> 的別名,如下圖 -</li>
</ol>
<pre class="brush:php;toolbar:false;">/**
    * The application's route middleware.
    *
    * These middleware may be assigned to groups or used individually.
    *
    * @var array
    */
   protected $routeMiddleware = [
    ....
    ....
       'dynamic_session' => \App\Http\Middleware\ChangeSessionValueDynamically::class,
    ....   
    ....
   ];</pre>
<ol start="4">
<li>將該中間件包含在路由中,如下所示 -</li>
</ol>
<pre class="brush:php;toolbar:false;">A) For Group Routes- 
Route::group([.., 'middleware' => ['dynamic_session', ..]], function () {
    ..
    Route::get('route_1', ['uses' => 'AbcController@index', 'as' => 'abc.index']);
    ..
}

B) OR For single Route-
Route::get('route_1', ['uses' => 'AbcController@index', 'as' => 'abc.index'])->middleware('dynamic_session');</pre></body></html>

            [good_count] => 0
            [floor] => 1
            [add_time] => 1693584802
            [status] => 1
            [level] => 0
            [answer_fid] => 0
            [fuid] => 0
            [fnickname] => 
            [answer_reply_id] => 0
            [fanyi] => 4,3,2,5,1
            [users] => Array
                (
                    [uid] => 1271571
                    [old_openid] => 
                    [openid] => 
                    [new_web_openid] => 
                    [web_openid] => 
                    [app_openid] => 
                    [union_id] => 
                    [apple_id] => 
                    [phone] => 
                    [pwd] => 
                    [nickname] => P粉978551081
                    [sex] => 0
                    [province] => 
                    [city] => 
                    [avatar] => //m.sbmmt.com/static/images/user_avatar.jpg
                    [qq] => 
                    [add_time] => 1652104069
                    [add_ip] => 61.233.97.243
                    [last_time] => 1652190562
                    [last_ip] => 61.233.97.243
                    [last_weixin_time] => 1652190562
                    [score_count] => 0
                    [now_money] => 0
                    [friend_count] => 0
                    [follow_count] => 0
                    [score_recharge_money] => 0.00
                    [is_check_phone] => 0
                    [is_follow] => 0
                    [status] => 1
                    [truename] => 
                    [birthday] => 0
                    [occupation] => 0
                    [message] => 
                    [email] => 
                    [is_teacher] => 0
                    [is_write] => 0
                    [write_count] => 0
                    [ask_count] => 0
                    [write_reply_count] => 0
                    [write_groom_count] => 0
                    [write_follow_count] => 0
                    [followmedia] => 
                    [news_favourite] => 
                    [news_praise] => 
                    [followcourse] => 
                    [publish_news_count] => 0
                    [wiki_count] => 0
                    [district] => 
                    [is_admin] => 0
                    [message_types] => 
                    [last_qdtime] => 0
                    [share_media_id] => 
                    [address] => 
                    [is_vip] => 0
                    [exa_jindu] => 
                    [exa_jin_course] => 
                    [vip_level] => 0
                    [zhiye] => 0
                    [xianzhuang] => 0
                    [is_change] => 0
                    [registration_id] => 
                    [xuni] => 1
                    [ask_num] => 0
                    [register_from] => 
                    [hits] => 5
                    [xuefen] => 0
                    [buqian_num] => 0
                    [id_card] => 
                    [id_card_zhengmian] => 
                    [id_card_fanmian] => 
                    [followsubject] => 
                    [goodsubject] => 
                    [goodcourse] => 
                    [followarticle] => 
                    [goodarticle] => 
                    [followask] => 
                    [goodask] => 
                )

            [ask_url] => //m.sbmmt.com/zh-tw/wenda/171438.html
            [reply_answer_list] => Array
                (
                )

            [reply_floor] => 1
        )

)