کریم کیمیائی فر
1 سال پیش توسط کریم کیمیائی فر مطرح شد
1 پاسخ

ارور در لاراول

سلام.
من یه پروژه لوکال برای تمرین کردن درست کردم و از لایووایر هم در پروژه استفاده کردم.
این ارور { Attempt to read property titleCompany on null } در صفحه ادمین این پروژه به من نمایش داده میشه:

Attempt to read property "titleCompany" on null

درواقع من اطلاعات فوتر صفحه اصلی پروژه رو گرفتم. درواقع Label های فوتر رو کپی کردم و در دیتابیس ، در یک جدول ذخیره کردم : اما زمانی که در صفحه ادمین اقدام به دریافت مقادیر میکنم ، این ارور نمایش داده میشه : درحالی که من همین کار هم در صفحه اصلی پروژه انجام دادم اما مقادیر به درستی نمایش داده میشه.
کد صفحه ادمین :

<?php

namespace App\Http\Livewire\Admin\Footer;

use App\Models\Admin\Footer\Footer;
use Illuminate\Support\Facades\DB;
use Livewire\Component;

class Titles extends Component
{
    public $titleCompany, $titleLabel1, $titleLabel2, $titleLabel3, $titleAddress, $titlePhone, $titleEmail, $titleSubscribe, $textSubscribe, $buttonSubscribe, $titleCopyright, $titleDesignedBy;
    public Footer $footer;

    public function __construct()
    {
        $footer = DB::table('footers')->first();
        // Variable
        $this->titleCompany = $footer->titleCompany;
        $this->titleLabel1 = $footer->titleLabel1;
        $this->titleLabel2 = $footer->titleLabel2;
        $this->titleLabel3 = $footer->titleLabel3;
        $this->titleAddress = $footer->titleAddress;
        $this->titlePhone = $footer->titlePhone;
        $this->titleEmail = $footer->titleEmail;
        $this->titleSubscribe = $footer->titleSubscribe;
        $this->textSubscribe = $footer->textSubscribe;
        $this->buttonSubscribe = $footer->buttonSubscribe;
        $this->titleCopyright = $footer->titleCopyright;
        $this->titleDesignedBy = $footer->titleDesignedBy;
    }

    public function render()
    {
        return view('livewire.admin.footer.titles');
    }

    public function update()
    {
        $footer = DB::table('footers')->limit(1);

        // Validation
        $this->validate([
            'titleCompany' => 'required',
            'titleLabel1' => 'required',
            'titleLabel2' => 'required',
            'titleLabel3' => 'required',
            'titleAddress' => 'required',
            'titlePhone' => 'required',
            'titleEmail' => 'required',
            'titleSubscribe' => 'required',
            'textSubscribe' => 'required',
            'buttonSubscribe' => 'required',
            'titleCopyright' => 'required',
            'titleDesignedBy' => 'required',
        ]);

        // Update
        $footer->update([
            'titleCompany' => $this->titleCompany,
            'titleLabel1' => $this->titleLabel1,
            'titleLabel2' => $this->titleLabel2,
            'titleLabel3' => $this->titleLabel3,
            'titleAddress' => $this->titleAddress,
            'titlePhone' => $this->titlePhone,
            'titleEmail' => $this->titleEmail,
            'titleSubscribe' => $this->titleSubscribe,
            'textSubscribe' => $this->textSubscribe,
            'buttonSubscribe' => $this->buttonSubscribe,
            'titleCopyright' => $this->titleCopyright,
            'titleDesignedBy' => $this->titleDesignedBy
        ]);

    }
}

این هم کد صفحه اصلی پروژه:

<?php

namespace App\Http\Livewire\Home\Layouts;

use Illuminate\Support\Facades\DB;
use Livewire\Component;

class Footer extends Component
{
    public function render()
    {
        $footer = DB::table('footers')->first();
        return view('livewire.home.layouts.footer', compact('footer'));
    }
}

fillable هم در مدل مربوطه مشخص کردم :

protected $fillable = [
        'titleCompany',
        'titleLabel1',
        'titleLabel2',
        'titleLabel3',
        'titleAddress',
        'titlePhone',
        'titleEmail',
        'titleSubscribe',
        'textSubscribe',
        'buttonSubscribe',
        'titleCopyright',
        'titleDesignedBy',
    ];

نسخه لاراول پروژه:

Laravel Framework 10.4.1

لطفا اگر مشکلی هست ، من رو کمک بدید🤝


ثبت پرسش جدید
Arshiamohammadei
تخصص : وب و هوش مصنوعی
@Arshiamohammadei 1 سال پیش مطرح شد
0

سلام وقت بخیر
ویژگی های titleCompany فراخوانی کن
یا میتونه مشکل از livewire باشه که هست
یه سری به این لینک بزن


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

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