mehdi SH
5 سال پیش توسط mehdi SH مطرح شد
0 پاسخ

null نشان دادن attributeGroup

سلام وقت همگی بخیر من به یک مشکلی برخوردم که اصلا نمیدونم چرا attribute_group را null نشان میدهد
مدل AttributeGroup

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AttributeGroup extends Model
{
    protected $table='attributesGroup';
    public function attributeValues()
    {
        return $this->hasMany(AttributeValue::class,'attributeGroup_id');
    }
}

مدل AttributeValue

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AttributeValue extends Model
{
    protected $table='attributesValue';
    public function attributeGroup()
    {
        return $this->belongsTo(AttributeGroup::class);
    }
}

کنترلر AttributeValue

<?php

namespace App\Http\Controllers\Admin;

use App\AttributeValue;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AttributeValueController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $attributeValue = AttributeValue::with('attributeGroup')->paginate(۱۰);
        return $attributeValue;
        return view('admin.attributeValue.index',compact('attributeValue'));
    }

نتیجه:

{
"current_page": ۱,
"data": [
{
"id": ۱,
"title": "نخ",
"attributeGroup_id": ۱,
"created_at": "۲۰۱۹-۰۱-۳۱ ۰۹:۲۴:۵۵",
"updated_at": "۲۰۱۹-۰۱-۳۱ ۰۹:۲۴:۵۸",
"attribute_group": null
}
],
"first_page_url": "http://۱۲۷.۰.۰.۱:۸۰۰۰/backend/attributeValue?page=۱",
"from": ۱,
"last_page": ۱,
"last_page_url": "http://۱۲۷.۰.۰.۱:۸۰۰۰/backend/attributeValue?page=۱",
"next_page_url": null,
"path": "http://۱۲۷.۰.۰.۱:۸۰۰۰/backend/attributeValue",
"per_page": ۱۰,
"prev_page_url": null,
"to": ۱,
"total": ۱
}

مقدار "attribute_group": null
لطفا راهنمایی کنید چیکار کنم !!!


ثبت پرسش جدید

به همدیگه کمک کنیم

به mehdi SH کمک کنید تا مشکل خودش را حل کند؛ این‌طور می‌توانیم با هم پیشرفت کنیم.

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام