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?
Don't use <?
, always use <?php
.
a php linter will also avoid this issue
So always use <?php
!!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.