简体   繁体   English

Laravel 包开发中的会话已过期

[英]Session Expired in Laravel Package Development

Description I am using livewire in a laravel package that will plug into a laravel project.描述 我在 laravel 包中使用 livewire,该包将插入 laravel 项目。 I succefully integrated Livewire in my package.我成功地将 Livewire 集成到我的软件包中。 The error i am fetching is This page has expired due to inactivty when i click a button that is binded to a component method.我正在获取的错误是当我单击绑定到组件方法的按钮时,由于不活动,此页面已过期。 I added csrf token in my base file like我在我的基本文件中添加了 csrf 令牌,例如

<meta name="csrf-token" content="{{ csrf_token() }}" />

Exact steps to reproduce重现的确切步骤

  • Create a package inside a laravel project.在 laravel 项目中创建一个包。 Just Render a Component只渲染一个组件
  • From Package Route(Follow the normal implementation of livewire).从包路由(遵循livewire的正常实现)。
  • Render from packages route file Route::get('/acc/test'VoucherComponent::class);从包路由文件渲染Route::get('/acc/test'VoucherComponent::class);
  • While Rending template from livewire php component make sure to add packagename before the view name like this.虽然来自 livewire php 组件的 Rending 模板确保在视图名称之前添加 packagename 像这样。
public function render(){ 
    return view('acc::livewire.voucher-component')->layout('acc::layouts.app'); 
   }

Stripped-down, copy-pastable code snippets Dependencies精简的、可复制粘贴的代码片段

    "php": "^7.3|^8.0",
    "illuminate/support": "^8.15",
    "livewire/livewire": "^2.3",
    "fruitcake/laravel-cors": "^2.0"

Browser: [ Chrome,]浏览器:[Chrome,]

Packages Route File包路由文件

    <?php

use Enam\Acc\Http\Livewire\AccHeadComponent;
use Enam\Acc\Http\Livewire\VoucherComponent;
use Illuminate\Support\Facades\Route;

use Enam\Acc\Http\Controllers\HomeController;

Route::get('/acc', function () {
    return view('acc::app');
});
Route::get('/acc/test', VoucherComponent::class);

Try applying web middleware to the routes尝试将web中间件应用于路由


use Enam\Acc\Http\Livewire\AccHeadComponent; 
use Enam\Acc\Http\Livewire\VoucherComponent; 
use Illuminate\Support\Facades\Route; 
use Enam\Acc\Http\Controllers\HomeController; 

Route::middleware(['web'])
->group(function() {
    Route::get('/acc', function () { return view('acc::app'); }); 
    Route::get('/acc/voucher-entry', 'Enam\Acc\Http\Controllers\HomeController@index'); 
    Route::get('/acc/test', VoucherComponent::class);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM