我更新了我的一个项目到Laravel Livewire V3,遇到了一些障碍。我的大多数路由都工作正常,但有几个由于某种原因抛出错误Can't set model as property if it hasn't been persisted yet
,对于我的生活,我无法弄清楚。我对我的大多数路线都没有问题--只是随机的几个,就像下面的路线。
web.php
...
Route::get('/evaluation/{evaluation}/edit', App\Livewire\Evaluations\Edit::class)->middleware(IsAdminMiddleware::class)->name('evaluation.edit');
...
编辑.php
<?php
namespace App\Livewire\Evaluations;
use App\Models\Evaluation;
use App\Models\Farm;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Livewire\Component;
class Edit extends Component
{
public $user, $farm, $evaluation, ...;
public function mount(User $user, Evaluation $evaluation, Farm $farm) {
$this->user = $user;
$this->farm = $farm;
$this->evaluation = $evaluation;
$this->farm_id = $evaluation->farm_id;
$this->user_id = $evaluation->user_id;
...
}
...
评测.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Evaluation extends Model
{
protected $guarded = [];
use SoftDeletes;
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function farm()
{
return $this->belongsTo(Farm::class, 'farm_id');
}
...
1条答案
按热度按时间watbbzwu1#
你会尝试更新livewire配置
(config/livewire.php)
吗: