tomasosho
1 week ago
106
5
General

ErrorException Creating default object from empty value

Posted 1 week ago by tomasosho

My controller

public function update(Request $request, $slug)

    {

        $request->validate([

            'name' => 'required',

        ]);

 

        // dd($slug);

 

        $category = ProductCategory::find($slug);

        $category->name = $request->input('name');

        $category->description = $request->input('description');

        $category->status = $request->input('status');

        $category->save();

        return redirect('category')->with('success','Great! updated successfully.');

    }

My slug value is null i don't know why

My Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;

class ProductCategory extends Model
{
    use Sluggable;

    /**
     * Return the sluggable configuration array for this model.
     *
     * @return array
     */
    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'name'
            ]
        ];
    }

    public function getRouteKeyName()
    {
        return 'slug';
    }

    // Table Name
    protected $table = 'product_categories';
    // Primary Key
    public $primaryKey = 'slug';
    // Timestamps
    public $timestamps = true;
}

Please sign in or create an account to participate in this conversation.