I am beginner in Laravel. I use in my project Laravel 5.8.
I have this code:
Model:
class ProductsCategory extends Model
{
protected $quarded = [];
protected $fillable = ['company_id', 'enable', 'name', 'url_address', 'level', 'parent_id', 'number'];
public $timestamps = true;
protected $table = 'products_category';
}
Migration:
public function up()
{
Schema::create('products_category', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->char('enable', 1)->default(0);
$table->string('name', 85)->nullable();
$table->string('url_address', 160);
$table->integer('level')->default(0);
$table->bigInteger('parent_id')->default(0);
$table->bigInteger('number')->default(0);
$table->timestamps();
$table->engine = "InnoDB";
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
});
}
I have many categories and subcategories in the database. Subcategories and categories are connected by parent_id.
How can I delete a record in such a way that all its subcategories are removed?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire