lundi 13 avril 2020

Laravel 5 on the category edit page, list selected in the top category select box

ı want Laravel 5 on the category edit page, list selected in the top category select box. what should I do. i stayed here. I can not move forward. help pls

<label for="top_category">Üst Kategorisi</label>
<select name="top_id" id="top_id" class="form-control">
    <option value="">Ana Kategori</option>

    @foreach($categoryList as $category)

            <option value="" ></option>
    @endforeach
</select>

controler

public  function form($id = 0){

        $entry = new Category; // sorun çıkarsa burayı kontrol et.
        if ($id>0){
            $entry = Category::find($id);
        }

        $categoryList = Category::all();
        return view('admin.category.form', compact('entry','categoryList'));

    }

Category Models

class Category extends Model
{
    use SoftDeletes;
    protected  $table       = "category";
    protected  $fillable    = ['category_name','slug','top_id'];
    // belirtilen kolona eklemeyi engeller
    //protected  $guarded     = ['slug'];
    // tüm kolonları serbest kılar
    protected  $guarded     = [];
    protected $dates = ['deleted_at'];

    public function products(){

        return $this->belongsToMany('App\Models\Product','product_category');
    }

    public function top_category(){
        return $this->belongsTo('App\Models\Category','top_id')->withDefault([
            'category_name' => 'Ana Kategori'
        ]);
    }

}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire