• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

<button aria-describedby="--stacks-s-tooltip-5b4w396w" aria-label="Bookmark" aria-pressed="false" class="js-bookmark-btn s-btn s-btn__unset c-pointer py4 js-gps-track" data-controller="s-tooltip" data-gps-track="post.click({ item: 1, priv: 0, post_type: 1 })" data-s-tooltip-placement="right" data-selected-classes="fc-yellow-600"></button><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" height="18" viewbox="0 0 19 18" width="19"></svg>

 

I'm on Laravel 8 with Livewire, currently have 3 models, Category, SubCategory and MenuItem for 3 tables. All the above models have separate livewire controllers and have the code for the CRUD operations respectively. I have separate views and routes to edit the above tables and they all have a eloquent relationship between each other. Now what I need to do here to is, I need to display all the three tables in a single view to carry out the CRUD operations.

I tried to achieve this by using the sub-view function, to pass the view and make the variables available to the specific view, but it didn't work out and I think it isn't the way to do it, was just trying to figure a workaround. I'm mentioning my models down below for referencing. Please help me with this. Thanks a lot for your time!

AppModelsCategory

class Category extends Model
{
    use HasFactory;

    protected $table = "categories";
    protected $fillable = ['sub_category_name'];

    public function SubCategories() {
        return $this->hasMany(SubCategory::class, 'category_id');
    }

    public function MenuItems() {
        return $this->hasManyThrough(
            'MenuItem::class',
            'SubCategory::class',
            'sub_category_id',
            'category_id'
        );
    }
}

AppModelsSubCategory

class SubCategory extends Model
{
    use HasFactory;

    protected $table = "sub_categories";
    protected $fillable = ['category_id', 'sub_category_name'];

    public function Categories() {
        return $this->belongsTo(Category::class, 'category_id');
    }

    public function MenuItems() {
        return $this->hasMany(MenuItem::class, 'sub_category_id');
    }
}

AppModelsMenuItem

class MenuItem extends Model
{
    use HasFactory;

    protected $table = "menu_items";
    protected $fillable = ['sub_category_id', 'item_name', 'item_description'];

    public function SubCategories() {
        return $this->belongsTo(SubCategory::class, 'sub_category_id');
    }
}