UploadedFile __toString()异常

时间:2016-06-14 14:12:01

标签: php laravel exception

我正在尝试插入数据库(存储功能),我收到此错误:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Method Illuminate\Http\UploadedFile::__toString() must not throw an exception

/home/vagrant/Sites/mySite/vendor/laravel/framework/src/Illuminate/Database/Connection.php
<?php

namespace Illuminate\Database;

use PDO;
use Closure;
use Exception;
use Throwable;
use LogicException;
use RuntimeException; // Highlighted
use DateTimeInterface;
use Illuminate\Support\Arr;
use Illuminate\Database\Query\Expression;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Query\Processors\Processor;
use Doctrine\DBAL\Connection as DoctrineConnection;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
use Illuminate\Database\Query\Grammars\Grammar as QueryGrammar;

Arguments
"Method Illuminate\Http\UploadedFile::__toString() must not throw an exception"

存储功能

/**
 * @param  Request $request
 * @param  ReviewProsConsRepository $reviewProsConsRepository
 * @param  ReviewTextRepository $reviewTextRepository
 * @return \Illuminate\Http\RedirectResponse
 */
public function store(Request $request, ReviewProsConsRepository $reviewProsConsRepository, ReviewTextRepository $reviewTextRepository, ReviewLanguageRepository $reviewLanguageRepository, ReviewCurrencyRepository $reviewCurrencyRepository)
{
    $review = $this->reviewRepository->create($request->all()); // Here is the error

    $this->mutualAction($request, $review->id, $reviewProsConsRepository, $reviewTextRepository, $reviewCurrencyRepository, $reviewLanguageRepository);

    return redirect()->route('manager.review.index')->with('message', 'Review criado com sucesso!');
}

- 编辑 -

ReviewRepository.php     

namespace App\Repositories;

use App\Models\Review;
use Housekeeper\Abilities\Adjustable;
use Housekeeper\Repository;

class ReviewRepository extends Repository
{
    use Adjustable;

    /**
     * Return the name of model that this repository used.
     *
     * @return string
     */
    protected function model()
    {
        return Review::class;
    }

}

我的图片上传会将 ID 从上传的图片返回到 cs_upload_id ,但是收到错误,我不明白为什么。

感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

不熟悉您正在使用的存储库软件包,但我猜测它会引发错误,因为您只是简单地传递了reviewRepository->create()方法$request->all()文本密钥对可以很好地处理到数据库,但也包括Illuminate\Http\UploadedFile,它可以找出如何处理。

我建议您以reviewRepository->create()方法可以理解的方式准备数据,而不是仅仅将$request->all()传递给它,并希望它能正常处理它。

希望这是有道理的。