diff --git a/app/Http/Controllers/Models/CategoryController.php b/app/Http/Controllers/Models/CategoryController.php index 3657a7ed..4e943fe7 100644 --- a/app/Http/Controllers/Models/CategoryController.php +++ b/app/Http/Controllers/Models/CategoryController.php @@ -61,7 +61,7 @@ class CategoryController extends Controller // Set the user ID $data['user_id'] = auth()->user()->id; - $data['parent_category'] = isset($data['parent_category']) && $data['parent_category'] > 0 ?: null; + $data['parent_category'] = isset($data['parent_category']) && $data['parent_category'] > 0 ? $data['parent_category'] : null; // Create the new link $link = Category::create($data); @@ -162,7 +162,7 @@ class CategoryController extends Controller $data = $request->all(); // Set the correct parent category - $data['parent_category'] = isset($data['parent_category']) && $data['parent_category'] > 0 ?: null; + $data['parent_category'] = isset($data['parent_category']) && $data['parent_category'] > 0 ? $data['parent_category'] : null; // Update the existing category with new data $category->update($data); diff --git a/app/Models/Category.php b/app/Models/Category.php index 0a26f211..2cf7002b 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -5,6 +5,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\SoftDeletes; +use App\Models\Link; +use App\Models\User; /** * Class Category @@ -64,7 +66,7 @@ class Category extends Model */ public function scopeParentOnly($query) { - return $query->where('parent_category', null); + return $query->whereNull('parent_category'); } /* @@ -77,7 +79,7 @@ class Category extends Model */ public function user() { - return $this->belongsTo('App\Models\User', 'user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** @@ -85,7 +87,7 @@ class Category extends Model */ public function links() { - return $this->hasMany('App\Models\Link', 'category_id'); + return $this->hasMany(Link::class, 'category_id'); } /** @@ -93,7 +95,7 @@ class Category extends Model */ public function childCategories() { - return $this->hasMany('App\Models\Category', 'parent_category'); + return $this->hasMany(Category::class, 'parent_category'); } /** @@ -101,6 +103,6 @@ class Category extends Model */ public function parentCategory() { - return $this->belongsTo('App\Models\Category', 'parent_category'); + return $this->belongsTo(Category::class, 'parent_category'); } }