Php 试图获得财产';浴室';非对象拉威尔的研究
很好,我有以下错误我不明白为什么,如果我所有的关系都很好,就我所见。。我想知道他们是否发现任何错误,以便他们不向我显示我的属性空间 财产模型Php 试图获得财产';浴室';非对象拉威尔的研究,php,sql,laravel,eloquent,Php,Sql,Laravel,Eloquent,很好,我有以下错误我不明白为什么,如果我所有的关系都很好,就我所见。。我想知道他们是否发现任何错误,以便他们不向我显示我的属性空间 财产模型 <?php namespace App; use Illuminate\Database\Eloquent\Model; class Propertie extends Model { // public function characteristic() { return $this->HasM
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Propertie extends Model
{
//
public function characteristic()
{
return $this->HasMany('App\Characteristic', 'property_id');
}
public function departament()
{
return $this->belongsTo('App\Departament');
}
public function municipality()
{
return $this->belongsTo('App\Detail');
}
public function detail()
{
return $this->belongsTo('App\Detail');
}
public function offer_type()
{
return $this->belongsTo('App\Offer_type','offer_type_id');
}
public function property_type()
{
return $this->hasOne('App\Property_type','id','property_type_id');
}
public function space()
{
return $this->belongsTo('App\Space', 'spaces_id');
}
public function ImgProperties()
{
return $this->hasMany('App\ImgProperties');
}
protected $fillable = [
'name', 'description', 'property_type_id', 'offer_type', 'spaces_id', 'departaments_id',
'municipalities_id', 'details_id', 'characteristics_id', 'images','url', 'lat', 'lng','direction','price'
];
空间迁移
*/
public function up()
{
Schema::create('spaces', function (Blueprint $table) {
$table->id();
$table->integer('property_id')->references('id')->on('properties')->onDelete('cascade');
$table->string('bedrooms');
$table->string('bathrooms');
$table->string('parking');
$table->string('area');
$table->timestamps();
});
}
指数法
public function index(Request $request)
{
$name = $request->get('name');
if($request->p_type){
$properties = Propertie::typeof($request->p_type);
}elseif($request->sorttype){
$properties = Propertie::sorttype($request->sorttype);
}else{
$properties = Propertie::with('space')->orderBy('id', 'ASC')
->name($name)
->paginate(5);
}
$property_type = Property_type::all();
$spaces = Space::all();
return view('properties.index',compact('properties','property_type'));
}
最近,它对我有效,但有时它不识别我的关系,我在索引中执行了dd,关系为空尝试将关系更改为此
public function space()
{
return $this->hasOne('App\Space', 'property_id');
}
public function space()
{
return $this->hasOne('App\Space', 'property_id');
}