小编Kar*_*ill的帖子

在 Laravel 5.5 中更新用户密码后防止注销

从 Laravel 5.3 开始,这个中间件被添加了......

\Illuminate\Session\Middleware\AuthenticateSession

虽然出于安全目的这绝对是一个好处,但它也负责在用户更改密码时注销用户(向用户显示登录页面)。

在 Laravel 5.5 中,我们如何防止用户在更改密码时被注销(被迫重新登录)?

php change-password laravel laravel-5.5 laravel-authentication

5
推荐指数
2
解决办法
3310
查看次数

如何在 Laravel 5.5 中通过急切加载关系进行排序?

下面的代码运行完美,并以 JSON 格式显示我的 API 的所有折扣产品。但我想要折扣表中按 id 排序的结果。就像是orderBy('discount.id', 'desc')。任何人都可以为此提供解决方案吗?如何将 orderBy 与表id中的列一起使用?discounthas()

public function promotions()
{
    return $this->prepareResult(true, Product::has('discount')->where([
        'company_id' => 1, 'is_active' => 1
    ])->with('category')->with('discount')->get(), [], "All Promotions");
}
Run Code Online (Sandbox Code Playgroud)

relationship laravel eloquent laravel-5

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

如何在 Laravel Mix 中使用 PurifyCSS?

我想在Laravel中使用PurifyCSS,但我无法让它工作。

Laravel:5.5.4

NPM:6.0.0

Node.js:8.10

代码

mix.styles([
    'resources/assets/css/panel/a.css',
    'resources/assets/css/panel/b.css',
    'resources/assets/css/panel/c.css',
    'resources/assets/css/panel/d.css',
], 'public/css/panel.css').options({
    purifyCss: {
        purifyOptions: {
            info: true,
            rejected: true,
            minify: true
        },
        paths: ['resources/views/admin-layout.blade.php'],
        verbose: true
    },
});
Run Code Online (Sandbox Code Playgroud)

我在互联网上搜索,但找不到任何东西。我想从所有 Blade 页面中删除未使用的 CSS。即使在此链接上,也没有人给出正确答案。即使 PurifyCSS 是第一个,它也不起作用。

谢谢您的帮助。

laravel laravel-5 laravel-mix purifycss laravel-5.5

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

使用嵌套集合直接在 Laravel Nova 中创建新资源

我正在使用 Laravel Nova。我有一个公司的资源,应该有一个地址。地址存储在不同的全局地址资源中。创建公司时如何直接添加地址信息?

这就是为什么我现在有这个字段:

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        Text::make('Company name', 'name')->sortable()->rules('required', 'max:255'),
        Text::make('Website', 'website')->hideFromIndex()->rules('nullable', 'url'),
        Markdown::make('Info')->alwaysShow(),
        BelongsTo::make('User')->searchable()->rules('required'),

        ## Address Resource needs
        Place::make('Streetname and number', 'address.address')->hideWhenUpdating(),
        Text::make('City', 'address.city')->hideWhenUpdating(),
        Text::make('Zipcode', 'address.postcode')->hideWhenUpdating(),
        Text::make('Latitude', 'address.latitude')->hideWhenUpdating(),
        Text::make('Longitude', 'address.longitude')->hideWhenUpdating(),

        // BelongsTo::make('Address')->searchable()->rules('required')->hideWhenCreating(),
    ];
}
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用。我在文档中看不到任何关于存储嵌套关系的内容;那可能吗?

laravel laravel-nova

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

Laravel 5.7/6.x 的 PhpDocumentor

这可能是一个非常新手的问题,但是,您到底如何使用 phpDocumentor 通过 Laravel 生成文档?在我的 Laravel 项目中,目录中没有phpdocvendor/bin,并且尝试通过 Composer 安装 phpDocumentor 失败(如 GitHub 页面上的建议)。

我找不到任何有关它的最新资源,我唯一幸运的是phpDocumentor.phar从终端运行该文件,但最新版本立即失败。

php phpdoc laravel laravel-5.7 laravel-6

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

Animate.css 似乎不适用于 Chrome 和 FF 中的 Laravel 7.10.3

我正在尝试在 Laravel 项目中使用Animate.css 。我使用以下命令安装了 Animate.css:

npm install animate.css --save
Run Code Online (Sandbox Code Playgroud)

我将其包含在 \resources\sass\app.scss 文件中:

@import "~animate.css/animate.css";
Run Code Online (Sandbox Code Playgroud)

然后我运行以下 npm 命令将其编译为 app.css:

npm run dev
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中查看页面源代码时,似乎包含 animate.css 但 HTML 元素没有动画。动画似乎可以在 Edge 中运行,但不能在 Chrome (v81.0.4044.138) 或 FF (v76.0) 中运行。

laravel animate.css laravel-7

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

Laravel 8 中未定义操作 Controller@store 的问题

我仍在探索 Laravel 8,但我的控制器的 store() 方法“未定义”有问题。

InvalidArgumentException Action PostsController@store 未定义。(查看:D:\Server\htdocs\app\resources\views\posts\create.blade.php)

我相信我实际上已经定义了它并且我使用了资源路线。

路线

Route::resource('posts', PostsController::class); 
Run Code Online (Sandbox Code Playgroud)

刀刃

@extends('layouts.app')

@section('content')
    <h1>Create Post</h1>

    {!! Form::open(['action' => 'PostsController@store', 'method' => 'POST']) !!}
    <div class="form-group">
        {{Form::label('title', 'Title')}}
        {{Form::label('title', ['class' => 'form-control','placeholder' =>'Title'])}}
    </div>
    <div class="form-group">
        {{Form::label('body', 'Body')}}
        {{Form::textarea('body', ['class' => 'form-control','placeholder' =>'Body'])}}
    </div>

    {{Form::submit('Submit',['class' =>'btn btn-primary'])}}
    {!! Form::close() !!}

@endsection
Run Code Online (Sandbox Code Playgroud)

控制器

class PostsController extends Controller
{
    public function create()
    {
        return view('posts.create');
    }

    public function store(Request $request)
    {
        $this->validate($request, [
            'title' => 'required',
            'body' => 'required'
        ]); …
Run Code Online (Sandbox Code Playgroud)

php controller laravel laravel-8

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

Laravel 8 - API、分页和资源。“链接” obj 到“元”键

我正在使用 Laravel 8 构建一个带有分页 JSON 的简单 API。

输出包含一个“链接”对象到“元”键:

{
  "data": [
    {
      . . .
    },
    {
      . . .
    }
  ],
  "links": {
    "prev": null,
    "first": "http://localhost/api/my-api?&page=1",
    "next": null,
    "last": "http://localhost/api/my-api?&page=2"
  },
  "meta": {
    "from": 1,
    "per_page": 400,
    "total": 477,
    "current_page": 1,
    "last_page": 2,
    "path": "http://localhost/api/my-api",
    "to": 400,
    "links": [
      {
        "url": null,
        "label": "Previous",
        "active": false
      },
      {
        "url": "http://localhost/api/my-api?&page=1",
        "label": 1,
        "active": true
      },
      {
        "url": "http://localhost/api/my-api?&page=2",
        "label": 2,
        "active": false
      },
      {
        "url": "http://localhost/api/my-api?&page=2",
        "label": "Next", …
Run Code Online (Sandbox Code Playgroud)

api pagination laravel-8

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

如何在 Laravel Mix 中使用 FullCalendar

我已经使用 npm 安装了 Fullcalendar 库包。

npm i --save @fullcalendar/core 
    @fullcalendar/interaction @fullcalendar/daygrid 
    @fullcalendar/timegrid @fullcalendar/list @fullcalendar/bootstrap
Run Code Online (Sandbox Code Playgroud)

我也将它包含在 app.js 中。

require('@fullcalendar/core');
require('@fullcalendar/bootstrap');
require('@fullcalendar/list');
require('@fullcalendar/timegrid');
require('@fullcalendar/daygrid');
require('@fullcalendar/interaction');
Run Code Online (Sandbox Code Playgroud)

但是,当尝试使用以下代码创建日历时:

var calendarEl = document.getElementById('calendar');
calendar = new Calendar(calendarEl, {
    plugins: [ 'interactionPlugin', 'bootstrapPlugin', 'dayGridPlugin', 'timeGridPlugin', 'listPlugin'],
});
Run Code Online (Sandbox Code Playgroud)

我收到错误...

Uncaught ReferenceError: Calendar is not defined at HTMLDocument.<anonymous>new Calendar

.

我究竟做错了什么?

我的 webpack.mix.js 看起来像这样:

const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css').version();
Run Code Online (Sandbox Code Playgroud)

编辑:

将我的 app.js 设置为:

window.FullCalendar = require('@fullcalendar/core');
window.bootstrapPlugin = require('@fullcalendar/bootstrap');
window.interactionPlugin = require('@fullcalendar/interaction');
window.listPlugin …
Run Code Online (Sandbox Code Playgroud)

fullcalendar laravel laravel-mix fullcalendar-5

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

如何从我的 Laravel 应用程序中撤消 Inertia.js

我在我的应用程序中撤消 Inertia.js 时遇到问题。当我启动我的应用程序时,我不小心输入了两个命令。

php artisan jetstream:install inertia --teams
Run Code Online (Sandbox Code Playgroud)

过了一会儿,我发现 Livewire 更适合我的项目。

php artisan jetstream:install livewire --teams
Run Code Online (Sandbox Code Playgroud)

我试图删除我所有的 Inertia.js 组件,但我npm watch会输出错误。我想知道我应该怎么做才能从我的项目中完全撤消 Inertia.js?

inertiajs npm laravel-livewire laravel-8 laravel-jetstream

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