【问题标题】:How to pass session variable in laravel using api如何使用 api 在 laravel 中传递会话变量
【发布时间】:2018-04-19 12:36:41
【问题描述】:

在刀片文件下方查找:

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

【问题讨论】:

  • 它会抛出任何错误吗?
  • 我不明白你到底想要什么
  • 我需要将用户 ID 作为会话变量传递。
  • 为什么不在刀片视图中简单地使用Auth::id()

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


【解决方案1】:

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

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

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 2011-11-16
    相关资源
    最近更新 更多