'Symfony\Component\Debug\Exception\FatalErrorException Trait not found in Laravel project [closed]
I have create a new trait within my Laravel project, but it doesn't work.
First I have created a folder called App\Traits
and my trait filename is UploadTrait.php
.
Content:
<?
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;
}
}
I try to use this trait in my controller as follows:
use App\Traits\UploadTrait;
class ProfileController extends Controller
{
use UploadTrait;
...
I'm getting the error message:
Symfony\Component\Debug\Exception\FatalErrorException Trait
'App\Traits\UploadTrait' not found
Can anyone help me to get this solve?
Solution 1:[1]
Don't use <?
, always use <?php
.
a php linter will also avoid this issue
So always use <?php
!!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andy Song |