2017-08-05 3 views
0

一部のモデルでSoftDeletesを使用するとこのエラーが発生します。 Sell::destroy($id);Sell::find($id)->delete();SoftDeletを使用するとエラーが発生する

(1/1) FatalThrowableError 

Type error: Too few arguments to function Illuminate\Database\Eloquent\Model::setAttribute(), 1 passed in /Users/ThunderBirdsX3/Desktop/Workspace/myproject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php on line 519 and exactly 2 expected 

at in HasAttributes.php (line 511) 
at Model->setAttribute(object(Carbon))in HasAttributes.php (line 519) 
at Model->setAttribute('', object(Carbon))in Model.php (line 1289) 
at Model->__set('', object(Carbon))in SoftDeletes.php (line 70) 
at Sell->runSoftDelete()in SoftDeletes.php (line 51) 
at Sell->performDeleteOnModel()in Model.php (line 751) 
at Model->delete()in SellController.php (line 176) 
at SellController->destroy(object(Request), '99') 
at call_user_func_array(array(object(SellController), 'destroy'), array(object(Request), 'sell' => '99'))in Controller.php (line 55) 
at Controller->callAction('destroy', array(object(Request), 'sell' => '99'))in ControllerDispatcher.php (line 44) 
at ControllerDispatcher->dispatch(object(Route), object(SellController), 'destroy')in Route.php (line 203) 
at Route->runController()in Route.php (line 160) 
at Route->run()in Router.php (line 574) 
at Router->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 30) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in SubstituteBindings.php (line 41) 
at SubstituteBindings->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Authenticate.php (line 43) 
at Authenticate->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in VerifyCsrfToken.php (line 65) 
at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ShareErrorsFromSession.php (line 49) 
at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in StartSession.php (line 64) 
at StartSession->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in AddQueuedCookiesToResponse.php (line 37) 
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in EncryptCookies.php (line 59) 
at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 102) 
at Pipeline->then(object(Closure))in Router.php (line 576) 
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php (line 535) 
at Router->dispatchToRoute(object(Request))in Router.php (line 513) 
at Router->dispatch(object(Request))in Kernel.php (line 176) 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))in Pipeline.php (line 30) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ForceHttps.php (line 27) 
at ForceHttps->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in TransformsRequest.php (line 30) 
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in TransformsRequest.php (line 30) 
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ValidatePostSize.php (line 27) 
at ValidatePostSize->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in CheckForMaintenanceMode.php (line 46) 
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php (line 148) 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53) 
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 102) 
at Pipeline->then(object(Closure))in Kernel.php (line 151) 
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php (line 116) 
at Kernel->handle(object(Request))in index.php (line 53) 

Sellモデル

<?php namespace App; 

use Illuminate\Database\Eloquent\Model; 
use Illuminate\Database\Eloquent\SoftDeletes; 

class Sell extends Model 
{ 
    use SoftDeletes; 

    /* The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = [ 
    'employee_id', 'product_id', 
    ]; 

    const UPDATED_AT = null; 

    public function Employee() 
    { 
    return $this->belongsTo(Employee::class)->withTrashed(); 
    } 

    public function Product() 
    { 
    return $this->belongsTo(Product::class)->withTrashed(); 
    } 

    public function Install() 
    { 
    return $this->hasOne(Install::class); 
    } 
} 

私は外にuse SoftDeletes;を削除した場合、それはすべてのエラーを取得できませんでした。 私のsellsテーブル、既にdeleted_atの列があります。モデルにprotected $dates = ['deleted_at'];を追加しても問題ありません。

コントローラ

<?php namespace App\Http\Controllers; 

use Validator, Entrust; 

use Illuminate\Http\Request; 
use Illuminate\Support\Facades\DB; 

use App\Employee; 
use App\Product; 
use App\Position; 
use App\Sell; 

class SellController extends Controller 
{ 

    ... 

    public function destroy(Request $request, $id) 
    { 
    if (!Entrust::can('sell-delete')) { abort(403); } 

    DB::beginTransaction(); 
    Sell::find($id)->Install()->delete(); //This line was not problem. 
    Sell::destroy($id); //This line has a problem 
    DB::commit(); 

    $request->session()->regenerateToken(); 

    return redirect()->back(); 
    } 
} 

DB構造 DB Structure

+1

フルスタックトレースを追加してくださいプロパティさかのぼります。 – systemovich

+0

@systemovich OK。 – ThunderBirdsX3

+0

'Sell :: destroy($ id);を呼び出すコードを追加し、データベーステーブル構造 –

答えて

0

モデルに

protected $dates = ['deleted_at']; 

Laravel Docs

これを追加してみてください

は、モデルのソフト削除を可能にするモデルに雄弁\ SoftDeletesトレイト\を照らし\ Databaseを使用して、あなたの$にdeleted_at列を追加するには

+0

+1です。この変更はLaravelでいつ起こったのですか?私はソフト削除を使用するモデルを持っており、保護されていない状態で正常に動作しています$ dates = ['deleted_at']; ... –

+0

うん、それは起こらない。私は同じエラーがあります。 – ThunderBirdsX3

関連する問題