如何在laravel中将特征用作路由控制器方法?

时间:2018-07-28 13:27:22

标签: php laravel

Target [App\Http\Controllers\Traits\FileUploadTrait] is not instantiable.

尝试将文件上传发送到此路由时出现此错误:

<?php

namespace App\Http\Controllers\Traits;

use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;

trait FileUploadTrait
{

    /**
     * File upload trait used in controllers to upload files
     */
    public function saveFiles(Request $request)
    {
      //some file upload code
    }

}

在我的路线上:

Route::post('upload/files', ['uses' => 'Traits\FileUploadTrait@saveFiles', 'as' => 'media.upload']);

如何将特征用作路径控制器@方法?

1 个答案:

答案 0 :(得分:1)

不能被调用的特征...这意味着:)您不能称它们为:Dlol,对不起-无法帮助自己...无论如何尝试这样的事情:)

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;

class MahController extends Controller {
   use App\Http\Controllers\Traits\FileUploadTrait;
}

不能“实例化”特质,而是将其添加到对象上。