小编Kyl*_*rst的帖子

“storage/logs/laravel-2019-11-22.log”无法打开:无法打开流:权限被拒绝

在生产服务器上输入我的站点时出现以下错误:

流或文件“/var/app/current/storage/logs/laravel-2019-11-22.log”无法打开:无法打开流:权限被拒绝

我尝试运行以下命令并在终端中拒绝权限:

php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan optimize:clear
Run Code Online (Sandbox Code Playgroud)

我跑了chmod -R 775 storage/logs/composer dump-autoload我能够毫无错误地进入我网站的主页。在网站上浏览了更多之后,我在各个区域而不是其他区域遇到了同样的错误:

又是同样的错误

流或文件“/var/app/current/storage/logs/laravel-2019-11-22.log”无法打开:无法打开流:权限被拒绝

我删除了以下文件并运行php artisan cahce:clear

/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php.php
Run Code Online (Sandbox Code Playgroud)

我见过的唯一其他建议是运行:

sudo chmod -R 777 storage/*
Run Code Online (Sandbox Code Playgroud)

在生产服务器上这似乎是一个坏主意,但似乎是赞成的答案。我应该给我的存储主管 777 权限吗?为什么?有没有另一种方法来解决这个问题?

编辑:

我正在尝试按照此处所述进行操作:

// set current user as owner and the webserver user as the group
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
// set directory permission to be 775
chmod -R 775 storage
chmod …
Run Code Online (Sandbox Code Playgroud)

permissions amazon-ec2 amazon-web-services laravel amazon-elastic-beanstalk

10
推荐指数
2
解决办法
2万
查看次数

解密模型值的访问器不起作用

我有一个使用访问器和修改器来加密模型值的特性:

trait Encryptable
{
    public function getAttribute($key)
    {
        $value = parent::getAttribute($key);

        if (in_array($key, $this->encryptable)) {
            $value = Crypt::decrypt($value);
            return $value;
        } else {
            return $value;
        }
    }

    public function setAttribute($key, $value)
    {
        if (in_array($key, $this->encryptable)) {
            $value = Crypt::encrypt($value);
        }

        return parent::setAttribute($key, $value);
    }
} 
Run Code Online (Sandbox Code Playgroud)

评论模型

protected $fillable = ['content','user_id','commentable_id', 'commentable_type'];
protected $encryptable = [
    'content'
];
Run Code Online (Sandbox Code Playgroud)

评论控制器

public function storePostComment(Request $request, Post $Post)
{
    $this->validate($request, [
        'content' => 'required',
    ]);

    $comment = $post->comments()->create([
        'user_id' => auth()->user()->id,
        'content' => $request->content …
Run Code Online (Sandbox Code Playgroud)

encryption accessor laravel laravel-6

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

如何制作一个 nextjs 中间件来检查经过身份验证的用户是否是管理员?

我本质上是在尝试构建下一个中间件来检查登录的 firebase 用户是否是管理员。问题是我无法获得经过 Firebase 身份验证的用户src/middleware.ts

代码

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { onAuthStateChanged } from 'firebase/auth';
import { auth } from './firebase';

// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
  if(request.url.includes('/admin')) {
    onAuthStateChanged(auth, (user) => {
      console.log(user);
    });
  }
  // return NextResponse.redirect(new URL('/', request.url))
}
Run Code Online (Sandbox Code Playgroud)

输出。console.log(user)null如果我将控制台更改为console.log(auth);我得到的currentUser: null,

我知道用户已登录,因为我可以使用相同的 firebase 函数来检索具有onClick. 例如这有效:

const …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-authentication next.js

5
推荐指数
0
解决办法
751
查看次数

调用未定义的方法 Illuminate\Database\Eloquent\Relations\BelongsToMany::routeNotificationFor()

我正在构建一个消息系统,在设置回复时通知对话中的每个用户。

消息通知.php

class MessageNotification extends Notification
{
    use Queueable;

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    public function toArray($notifiable)
    {
        return [
            'data' => 'Messenger notification'
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

收件箱控制器

public function reply($hashedId, Request $request)
{
    $this->validate($request, [
        'body' => 'required',
    ]);

    $conversation = Conversation::where('hashed_id', $hashedId)->first();

    $users = $conversation->participants();

    //dd($conversationUserIds);

    $notifications = Notification::send($users, new MessageNotification());

    $message = $conversation->messages()->create([
        'sender_id' => auth()->user()->id,
        'body' => $request->body, …
Run Code Online (Sandbox Code Playgroud)

notifications laravel laravel-6

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

安装和编译:tailwind 类不适用于 laravel 6 的全新安装

我尝试在全新安装的 Laravel 6 上安装 tailwind.css。我添加了一些 tailwind 类,但它不起作用。没有错误,什么都没有。

安装

npm install tailwindcss

资源/sass/app.scss

@tailwind base;

@tailwind components;

@tailwind utilities;
Run Code Online (Sandbox Code Playgroud)

生成了一个配置文件:

./node_modules/.bin/tailwind init

webpack.mix.js

var tailwindcss = require('tailwindcss');

mix.js('resources/js/app.js', 'public/js')
  .sass('resources/sass/app.scss', 'public/css')
  .options({
    processCssUrls: false,
    postCss: [ tailwindcss('tailwind.config.js') ],
});
Run Code Online (Sandbox Code Playgroud)

编译

npm run dev

我添加了一些html:

<div class="rounded-lg p-6 bg-red-400">
  <img class="h-16 w-16 rounded-full mx-auto" src="https://picsum.photos/50/50">
  <div>
    <h2 class="text-lg text-red-400">Erin Lindford</h2>
    <div>Customer Support</div>
    <div>erinlindford@example.com</div>
    <div>(555) 765-4321</div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我没有收到任何错误或任何东西。但是,仍然安装了引导程序,但我不确定这是否重要。

laravel webpack tailwind-css

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