小编jos*_*son的帖子

三元表达式中的枚举类

PHP 最近才引入枚举。我正在 Laravel 项目中尝试它们。我在这里有我的枚举类:

namespace App\Enums;

enum AlertType
{
    case SUCCESS;
    case ERROR;
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建一个警报类,该类将采用构造函数中的枚举来设置警报的严重性,这将决定向用户呈现的颜色。这是该类:

<?php

namespace App\View\Components;

use App\Enums\AlertType;
use Illuminate\View\Component;

class Alert extends Component
{
    public string $contextClass;

    public function __construct(public string $message, AlertType $alertType = AlertType::SUCCESS)
    {
        $this->setContextClassFromAlertType($alertType);
    }

    public function setContextClassFromAlertType(AlertType $alertType)
    {
        $this->contextClass = ($alertType === AlertType::SUCCESS ? 'success' : 'error');
    }

    public function getClassListFromType()
    {
        return [
            'border-' . $this->contextClass,
            'text-' . $this->contextClass
        ];
    }

    public function render()
    {
        return view('components.alert', [
            'class' => …
Run Code Online (Sandbox Code Playgroud)

php enums laravel php-8.1

6
推荐指数
2
解决办法
2336
查看次数

vue-devtools始终与nuxt.js禁用

我正在使用nuxt.js v2.3.0创建一个新项目。当我npm run dev在我的想法控制台中运行时,所有内容都能正确编译,但是当我转到页面时,出现以下错误:Nuxt.js + Vue.js is detected on this page. Devtools inspection is not available because it's in production mode or explicitly disabled by the author.

这是我的nuxt.config.js:

const pkg = require('./package');

module.exports = {
  mode: 'spa',

  dev: true,
  /*
  ** Headers of the page
  */
  head: {
    title: pkg.name,
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: pkg.description }
    ],
    link: [
      { rel: 'icon', …
Run Code Online (Sandbox Code Playgroud)

vue.js nuxt.js vue-devtools

3
推荐指数
2
解决办法
2772
查看次数

Laravel 5.6 通过 oauth/令牌挂起

我已经使用 Laravel Passport 安装设置了一个新的 Laravel 5.6 安装。如果我使用 Postman向http://127.0.0.1/oauth/token发出帖子请求,我会得到一个有效的令牌:

要求

POST /oauth/token HTTP/1.1
Host: 127.0.0.1:8000
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Cache-Control: no-cache
Postman-Token: 99529c07-0fe3-38a8-54cf-8b80a9dd5fbd

{ 
    "grant_type" : "password",
    "client_id" : 4, 
    "client_secret" : "Ib1UOS7BK12tFxOilqwea1XGJhrExbVYe8B7r8wK",
    "username" : "mail@mail.com",
    "password" : "password"
}
Run Code Online (Sandbox Code Playgroud)

回复:

{
    "token_type": "Bearer",
    "expires_in": 31536000,
    "access_token": "eyJ0eXAiOiJKV1.....",
    "refresh_token": "def5020026dfeb6f91f6a9....."
}
Run Code Online (Sandbox Code Playgroud)

我不希望我的用户直接访问它,所以我在 routes/web.php 文件中设置了一个路由:

Route::post('login', 'API\AuthController@login');
Run Code Online (Sandbox Code Playgroud)

我的 AuthController 看起来像:

<?php

namespace App\Http\Controllers\API;

use App\OAuth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller as Controller;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use App\User;

class AuthController extends …
Run Code Online (Sandbox Code Playgroud)

curl oauth laravel-passport laravel-5.6

0
推荐指数
1
解决办法
2650
查看次数