錯誤消息ErrorException在Macroable.php線74
方法wardrobeimage不存在。 (View:C:\ laragon \ www \ wasamar \ resources \ views \ main_app \ admin \ wardrobe.blade.php)
我有這個問題,當我想打電話給我的衣櫃圖像類來顯示衣櫃的圖像。
衣櫃模型
<?php
namespace App\Wasamar;
use Illuminate\Database\Eloquent\Model;
class Wardrobe extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'wardrobes';
public function wardrobeimage(){
return $this->hasMany('App\Wasamar\Wardrobeimage','wardrobe_id');
}
}
衣櫃Image類
<?php
namespace App\Wasamar;
use Illuminate\Database\Eloquent\Model;
class Wardrobeimage extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'wardrobeimages';
function wardrobe(){
return $this->belongsTo('App\Wasamar\Wardrobe','id');
}
}
所以,當我做到這一點提示錯誤
<?php
$wardrobeAttires = Wardrobe::where('user_id',$user->id)->get();
?>
$wardrobeAttires->wardrobeimage()->where('wardrobe_attire_view',0)->get();
' - > get()'返回一個集合。你想要做' - > first()'這會給你一個單一的衣櫃模型。那麼你應該可以在該模型上調用'wardrobeimage()'方法。 – jszobody
@jszobody基於你對我的建議,使用first()而不是get(),它確實有效,但那不是我想要實現的。我希望能夠穿過衣櫥圖像服裝並展示它們。 – udemethegrtman
然後先循環收集。您無法直接在集合上調用模型方法。 – jszobody