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

时间:2018-04-19 12:36:42

标签: laravel laravel-5 laravel-5.2 laravel-5.3 whmcs

在下面找到刀片文件:

@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中传递会话变量的解决方案,以便在我的视图文件中显示基于客户端的域。

1 个答案:

答案 0 :(得分:2)

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

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

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

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

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

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

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