lundi 19 mars 2018

Showing category title

I've created a page where you can select a parent category for an item. My database has a column called productparentcat_id that has the category's ID.

Then problem I'm having is even though the correct ID is saved, when I try to get it to show when I try to edit the page it doesn't show. I get this error

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'productscat.id' in 'field list' (SQL: select productscat.id from products where products.productparentcat_id = 347 and products.productparentcat_id is not null

I know that the sql statement is wrong and that my code if wrong, but I can't see where I've went wrong. I'm hoping someone with fresh eyes can spot it.

My edit function in my ProductsController

    public function edit($id)
{
    $products = Product::find($id);

    $category_options = ProductsCat::pluck('title', 'id');

    $selected_parent = $products->productParentCat()
                                ->pluck('id')
                                ->toArray();


    if(is_null($products)){
        return redirect()->route('products.edit');
    }

    return view('products::admin.edit', compact('selected_parent', 'products', 'category_options'));
}

My edit.blade.php

    <div class="form_input">
    <div>
        {!! Form::label('productparentcat_id', 'Parent Category') !!}
    </div>
    <div>
        {!! Form::select('productparentcat_id', $category_options, $selected_options, array("class" => "form-control")) !!}
    </div>
</div>

My Product model

public function productParentCat()
{
    return $this->hasMany('App\Modules\Products\Models\Product', 'productparentcat_id');
}

If there is anything else I need to give please let me know.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2HL75yC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire