如何使用 api 在 laravel 中传递 session 变量

How to pass session variable in laravel using api

在 blade 文件下面找到:

@foreach($product1['domains']['domain'] as $product)
    <tr role="row">
    <td  class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Rendering engine: activate to sort column ascending" aria-sort="descending">1</td>
     <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1"aria-label="Browser: activate to sort column ascending">
      <a href=""  style="color:#23b7e5" data-toggle="modal" data-target="#myModal1">      
      {{$product['domainname']}}
      </a>
      </td>
      <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending">
     {{$product['regdate']}}
     </td>
     <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending">

    {{$product['expirydate']}}
    </td>


    <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending">Renew</td>

    </tr>
    @endforeach

在路由代码下方查找:

    Route::get('/mydomains','InvoiceTicketController@set');

控制器代码如下:

class InvoiceTicketController extends Controller
{

    public function set(){
        $product1=Whmcs::GetClientsDomains([]);
        return view('clientlayout.main.mydomains',compact('product1'));
    }
}

给我一个解决方案,在 laravel 中传递 session 变量,以在我的视图文件中显示基于客户端的域。

只需使用辅助函数 session()。

在控制器上你可以这样使用:

$value = $request->session()->get('key');

要在会话中存储数据,您可以这样做:

$request->session()->put('key', 'value');

在视图上,您​​可以使用函数会话来检索值:

{{ session(['key' => 'value']) }}