【发布时间】:2020-03-18 09:21:54
【问题描述】:
我正在尝试编辑和更新透视表数据,但我无法编辑。我在listings 和project_types 表之间有belongsToMany 关系。
这是我的 Listing.php 模型...
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Listing;
use App\ProjectType;
class Listing extends Model
{
protected $primaryKey = 'lstId';
protected $guarded = [];
public function proType(){
return $this->belongsToMany(ProjectType::class, 'properties_searchable_tags', 'lstId', 'typeId');
}
}
这是我的 ProjectType.php 模型...
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\City;
use App\Listing;
use App\ProjectType;
class ProjectType extends Model
{
use SoftDeletes;
protected $primaryKey = 'typeId';
protected $guarded = [];
protected $with = ['listing'];
public function propertytype(){
return $this->belongsTo(ProjectType::class, 'ctId','ctId');
}
public function listing()
{
return $this->belongsToMany(ProjectType::class, 'properties_searchable_tags','typeId','lstId');
}
}
这是我的 ProjectTypeContrroller.php 文件..
public function edit($projectType)
{
$city=City::all();
$locality=Locality::all();
$listingdata=Listing::all();
$propertyType=ProjectType::findOrFail($projectType);
return view('admin.propertytype.edit', compact('city', 'propertyType','locality','listingdata'));
}
这是我的edit.blade.php
<tbody>
@foreach($listingdata as $lists)
<tr>
<td style="width: 10%">
<div class="checkbox">
<label>
<input type="checkbox" class="icheck" name="{{$lists->proptype}}" id="proptype[0]" value="{{$lists->typeId}}">
}
</label>
</div>
</td>
<td>{{$lists->prop_name}}</td>
@if($lists->property->builder)
<td>{{$lists->property->builder->name}}</td>
@endif
<td>{{$lists->property->proLocation->locations}}</td>
<td>{{$lists->property->proLocality->name}}</td>
</tr>
@endforeach
</tbody>
【问题讨论】:
标签: laravel eloquent laravel-6 laravel-6.2