一部のモデルで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();
}
}
フルスタックトレースを追加してくださいプロパティさかのぼります。 – systemovich
@systemovich OK。 – ThunderBirdsX3
'Sell :: destroy($ id);を呼び出すコードを追加し、データベーステーブル構造 –