久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      詳解Laravel應(yīng)用中模擬用戶的方法(附代碼步驟)

      本篇文章給大家?guī)砹岁P(guān)于Laravel的相關(guān)知識,其中主要介紹了Laravel Nova是什么?Laravel中應(yīng)用中怎么模擬用戶?感興趣的朋友,下面一起來看一下,希望對大家有幫助。

      詳解Laravel應(yīng)用中模擬用戶的方法(附代碼步驟)

      Laravel Nova 的一個新特性是在控制面板中模擬用戶。這很方便,原因很多。但對于我而言,當收到錯誤報告或問題,并希望看到用戶所看到的內(nèi)容時,模擬他們可以節(jié)省大量時間,因為您可以看到他們所看到的。

      如果你也想在你的 Laravel 應(yīng)用中實現(xiàn)該功能,Laravel Impersonate 包讓這一點變得簡單。

      步驟 1. 安裝軟件包

      composer require lab404/laravel-impersonate
      登錄后復制

      然后,打開 config/app.php 并將其添加都 providers 數(shù)組:

      'providers' => [     // ...     Lab404ImpersonateImpersonateServiceProvider::class, ],
      登錄后復制

      之后,打開 Models/User 并添加 trait:

      use Lab404ImpersonateModelsImpersonate;  class User extends Authenticatable {     use Impersonate;
      登錄后復制

      步驟 2. 模擬路由

      Laravel Impersonate 包包含了一些模擬用戶的方法,不過我發(fā)現(xiàn)將路由宏添加到 routes/web.php 文件中是最為簡便的方法:

      Route::impersonate();
      登錄后復制

      這給你一些命名路由:

      // Where $id is the ID of the user you want to impersonate route('impersonate', $id)  // Or in case of multi guards, you should also add `guardName` (defaults to `web`) route('impersonate', ['id' => $id, 'guardName' => 'admin'])  // Generate an URL to leave the current impersonation route('impersonate.leave')
      登錄后復制

      步驟 3. Laravel Blade 模擬用例

      Laravel Impersonate 設(shè)置就緒后,你可以使用 其中模板 helpers:

      @canImpersonate($guard = null)     <a href="{{ route('impersonate', $user->id) }}">Impersonate this user</a> @endCanImpersonate
      登錄后復制

      然后反轉(zhuǎn):

      @impersonating($guard = null)     <a href="{{ route('impersonate.leave') }}">Leave impersonation</a> @endImpersonating
      登錄后復制

      步驟 4. 高級設(shè)置

      另一個你可能會考慮的是,限制誰可以模擬其他用戶,以及那些用戶可以被模擬。在 Models/User 中,你可以添加以下方法:

      /**  * By default, all users can impersonate anyone  * this example limits it so only admins can  * impersonate other users  */ public function canImpersonate(): bool {     return $this->is_admin(); }  /**  * By default, all users can be impersonated,  * this limits it to only certain users.  */ public function canBeImpersonated(): bool {     return ! $this->is_admin(); }
      登錄后復制

      推薦學習:《laravel視頻教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號