繁体   English   中英

在 Laravel 项目中找不到 Symfony\\Component\\Debug\\Exception\\FatalErrorException Trait

[英]Symfony\Component\Debug\Exception\FatalErrorException Trait not found in Laravel project

我在我的 Laravel 项目中创建了一个新特性,但它不起作用。

首先,我创建了一个名为App\\Traits的文件夹,我的特征文件名为UploadTrait.php

内容:

<?

namespace App\Traits;

use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;

trait UploadTrait
{
    public function uploadOne(UploadedFile $uploadedFile, $folder = null, $disk = 'public', $filename = null)
    {
        $name = !is_null($filename) ? $filename : Str::random(25);

        $file = $uploadedFile->storeAs($folder, $name.'.'.$uploadedFile->getClientOriginalExtension(), $disk);

        return $file;
    }
}

我尝试在我的控制器中使用这个特性,如下所示:

use App\Traits\UploadTrait;

class ProfileController extends Controller
{
    use UploadTrait;

    ...

我收到错误消息:

Symfony\\Component\\Debug\\Exception\\FatalErrorException 特性

'App\\Traits\\UploadTrait' 未找到

谁能帮我解决这个问题?

不要使用<? , 始终使用<?php

php linter 也可以避免这个问题

所以总是使用<?php !!!

暂无
暂无

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

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