category hierarchy laravel
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
// One level child
public function child() {
return $this->hasMany('App\Category', 'parent_category_id');
}
// Recursive children
public function children() {
return $this->hasMany('App\Category', 'parent_category_id')
->with('children');
}
// One level parent
public function parent() {
return $this->belongsTo('App\Category', 'parent_category_id');
}
// Recursive parents
public function parents() {
return $this->belongsTo('App\Category', 'parent_category_id')
->with('parent');
}
}
Also in PHP:
- am pm in php
- Route pattern cannot reference variable name more than once. laravel
- date 'F' what is it
- file in array
- event angular check it right click
- SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; m ax key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`e mail`))
- convert image to base64 php
- create crandon string php
- does contains string character php
- Undefined offset: 0 at laravel\framework\src\Illuminate\Routing\Router.php
- create project with laravel 7
- Exception.php
- check where key in associative array have a value
- echo console.log
- check if next key is array or object in php
- error showing code in php
- error_reporting(e_all) in php
- Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:cer
- date format pgp
- datetime format laravel
- clear cache config laravel
- date(t) php
- cacert file_get_contents openssl
- convert date to timestamp in php