小编Tam*_*mma的帖子

Laravel 时间戳(来自 json 响应)与 artisan & mysql select 命令生成的时间戳不同

2020-08-09TL;DR: json 响应中没有。

我今天刚刚在我的项目中发现了一个奇怪的行为Laravel 7.x。正如上面标题所提到的, json 响应的created_atupdated_at与 artisan 命令生成的响应不同。

app/config.php当我将默认时区从UTCfrom更改为 时,就会出现问题Asia/Jakarta。为了清楚起见,这是我的查询的一些结果:

mysql> select * from field_reports

+----+------------+-----------+---------+-------------+------------------------+--------------------------------------------+---------------------+---------------------+
| id | company_id | branch_id | user_id | title       | chronology             | images                                     | created_at          | updated_at          |
+----+------------+-----------+---------+-------------+------------------------+--------------------------------------------+---------------------+---------------------+
|  1 |          1 |         1 |       1 | example     | example chronology     | [{"url": "some_url", "path": "some_path"}] | 2020-08-08 16:02:53 | 2020-08-08 16:29:46 |
|  2 |          1 |         1 …
Run Code Online (Sandbox Code Playgroud)

php laravel

10
推荐指数
1
解决办法
4124
查看次数

在 Vue-Router 上替换路由时出现导航重复错误

我有上面标题中定义的 vue 路由器问题。

假设我有一个router-view当用户从页面选择器组件中选择页面时动态呈现页面。我期待的是我必须让网址是这样的:

http://localhost:port/editor/{appSlug}/layout-editor/page/{pageSlug}

但相反,我得到了这个:

http://localhost:port/editor/{appSlug}/layout-editor/page/{pageSlug}-randomString

控制台显示此错误:

NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "导航到当前位置 ("/editor/penerimaa.../page/input-pendaftaran-edrpekvl") 是不允许的", stack: "Error? at new NavigationDuplicated (webpack-int…/node_modules/vue/dist/vue.runtime.esm.js:3876:9)"}`

我已经检查了路由器文件,但仍然无法找出我的路由有什么问题。我也尝试了这个问题的解决方案,但仍然有这个错误。

有人可以帮我解决这个问题吗?

请看一下我的代码:

router.js

import Vue from 'vue'
import Router from 'vue-router'
import store from './store/index'

import Home from './views/home/Index.vue'

Vue.use(Router)

let router = new Router({
  mode: 'history',
  linkActiveClass: 'active',
  linkExactActiveClass: 'exact-active',
  routes: [{
      path: '/',
      name: 'home',
      component: Home,
      meta: {
        requiresAuth: true
      }
    },
    {
      path: '/login',
      name: 'login',
      // route …
Run Code Online (Sandbox Code Playgroud)

vue.js

6
推荐指数
1
解决办法
1万
查看次数

如何正确使用 GetX 与 TextField 和一些服务器端验证?

我正在使用get包进行项目的状态管理。但是我对表单输入和验证的实现感到困惑,因为我在文档中找不到任何示例。我对这个问题有一些疑问。

  1. 我应该为每个动作创建单独的控制器吗?喜欢PageOneControllerPageOneFormController
  2. 状态改变时如何防止父级重建子级?
  3. 如何在Model().obs对象内部添加数据时触发重建?

正如我上面在第 1 点提到的,我发现使用单独的控制器有点重复和不必要,但是在多个地方使用相同的控制器会阻止我在离开子页面时重置状态,因为控制器只在我离开时被破坏已初始化状态的页面。为避免我的解释造成任何混淆,请查看下图。

视觉解释

在第 2 点,我们知道TextField小部件接受errorText显示仅接受字符串的错误消息。考虑到这个包,当我尝试通过onChanged: (value) {}事件每次我在其中键入一个值时,它都会重建整个小部件,这导致输入指示器停留在开头。

在这种情况下,第 2 点不再发生,但现在它根本不会更新错误状态,并且会继续显示错误消息,即使我在其上键入新值也是如此。

请帮忙,这是我的脚本:

education_info_create_page.dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:prismahrfinal/app/controllers/account_info/education_info_controller.dart';
import 'package:prismahrfinal/app/ui/widgets/form_input.dart';

class EducationInfoCreatePage extends GetWidget<EducationInfoController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text('Add Education Info'),
            floating: true,
          ),
          SliverToBoxAdapter(
            child: Padding(
              padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
              child: Column(
                children: <Widget>[
                  Obx(
                    () => FormInput( …
Run Code Online (Sandbox Code Playgroud)

flutter

6
推荐指数
1
解决办法
6955
查看次数

Laravel 5.8 POST 请求总是抛出欢迎页面

我正在尝试使用邮递员测试我的 API,但是当我点击POST请求时,它总是让我进入欢迎页面。我已经在里面设置了 XSRF 令牌,但仍然无法正常工作。

这是我的api.php路线:

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});
Route::resource('products/{product}/feedbacks', 'FeedbackController');
Run Code Online (Sandbox Code Playgroud)

这是我的商店方法FeedbackController

/**
 * Store a newly created resource in storage.
 *
 * @param  \App\Http\Requests\StoreFeedback  $request
 * @return \Illuminate\Http\Response
 */
public function store(Product $product, StoreFeedback $request)
{
   $product->addFeedback(
      $request->validated()
   );

   return response()->json([
      "status" => "success",
      "message" => "Your feedback has been submitted."
   ], 200);
}
Run Code Online (Sandbox Code Playgroud)

这是我的web.php文件:


Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::resource('product-categories', 'ProductCategoryController')->parameters([ …
Run Code Online (Sandbox Code Playgroud)

php laravel

5
推荐指数
1
解决办法
3030
查看次数

当用户更改应用程序的主题时,字体的主题无法正确重建(GetX 状态管理)

我已经创建了一个“几乎完成”的应用程序,但是在切换主题方面存在一些问题。我正在使用getxandget_storage进行状态管理。

我还使用了很多static主题类型,因为我认为它不应该一直被重建。它适用于其他组件,但不适用于文本。它的行为就像这样,有点奇怪..

问题可视化

我不知道是什么原因造成的,我应该避免使用static主题类吗?请看一下我的脚本,如果我做错了什么,请随时告诉我。

main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await GetStorage.init();
  ...
  ...
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  final box = GetStorage();

  @override
  Widget build(BuildContext context) {
    return SimpleBuilder(
      builder: (_) {
        bool isDark = box.read('darkMode');
        return GetMaterialApp(
          ...
          theme: CustomTheme.light,
          darkTheme: CustomTheme.dark,
          themeMode: isDark == null
              ? ThemeMode.system
              : isDark ? ThemeMode.dark : ThemeMode.light,
          ...
        );
      },
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

custom_theme.dart

class CustomTheme {
  static ThemeData get light { …
Run Code Online (Sandbox Code Playgroud)

flutter

5
推荐指数
1
解决办法
1505
查看次数

如何修复命名空间枚举的类未找到错误?

enums在 Laravel 项目的根目录中手动创建了一个文件夹。目前,只有一个文件被调用TransactionTypes,我想在迁移中使用它(将来也在另一个文件中)。但是,当我测试该应用程序时,它会抛出错误。

Class "Enums\TransactionTypes" not found
Run Code Online (Sandbox Code Playgroud)

我使用这个枚举的迁移看起来像这样

<?php

use App\Models\Foodstuff;
use Enums\TransactionTypes;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('transactions', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(Foodstuff::class);
            $table->enum('type', TransactionTypes::cases()); // HERE
            $table->unsignedInteger('stock');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('transactions');
    }
};

Run Code Online (Sandbox Code Playgroud)

我已经namespace在我的枚举中声明了 a

<?php …
Run Code Online (Sandbox Code Playgroud)

php laravel

5
推荐指数
1
解决办法
4650
查看次数

Bloc 事件只触发一次

我按照这种方法来管理块并保存一些代码行。

我想从我的 API 中获取数据。我想通过initState方法和调用来做到这一点myBloc.add(MyEvent())。但问题是,它只被调用了一次。

我已经在几个博客上搜索并尝试了一些解决方案,这是官方的 Github 存储库问题,但仍然无法正常工作。我发现了一个类似的问题,但由于我没有使用任何依赖注入或单例,我无法找到问题的确切位置和位置,而且我的问题仍未解决。

这是我迄今为止尝试过但仍未解决问题的方法:

  1. 从集团中删除 Equatable
  2. 硬重新加载设备
  3. 运行flutter clean命令
  4. 重新运行应用

为了清楚起见,请看一下这段录音。

视觉解释

最后,这是我的脚本的样子:

leave_bloc.dart

import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:flutter_prismahr/app/data/models/leave_model.dart';
import 'package:flutter_prismahr/app/data/repositories/leave_repository.dart';
import 'package:meta/meta.dart';

part 'leave_event.dart';
part 'leave_state.dart';

class LeaveBloc extends Bloc<LeaveEvent, LeaveState> {
  LeaveBloc() : super(LeaveInitial());

  final LeaveRepository repository = LeaveRepository();

  @override
  Stream<LeaveState> mapEventToState(
    LeaveEvent event,
  ) async* {
    print('TRIGGERED EVENT IS: $event');
    if (event is LeaveScreenInitialized) {
      yield LeaveLoading();

      try {
        final response = await …
Run Code Online (Sandbox Code Playgroud)

flutter bloc flutter-bloc

2
推荐指数
1
解决办法
1659
查看次数

标签 统计

flutter ×3

laravel ×3

php ×3

bloc ×1

flutter-bloc ×1

vue.js ×1