view src/Generator/Model/stubs/model.stub @ 24:31109c61ce02 codex

Refactor RelationshipNavigator formatting and implement belongsTo, hasMany, belongsToMany injection in ModelGenerator
author Luka Sitas <sitas.luka.97@gmail.com>
date Tue, 22 Apr 2025 21:37:44 -0400
parents 827efbf4d73c
children 555bfaa500ac
line wrap: on
line source

<?php

namespace {{ namespace }};

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class {{ class }} extends Model
{
    //use HasFactory;
    use SoftDeletes;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = '{{ tableName }}';

		/**
     * The model's default values for attributes.
     *
     * @var array
     */
    protected $attributes = [
			# {{ atributeInsertPoint }}
    ];

		protected $fillable =[
			# {{ fillableInsertPoint }}
		];


		public static function boot() : void {
			parent::boot();

			self::creating(function ($item) {
				$item->created_by = \Auth::user()->id;
				$item->updated_by = \Auth::user()->id;
			});

			self::saving(function ($item) {
				$item->updated_by = \Auth::user()->id;
			});
		}


		//relations

		// BelongsTo
		# {{ belongs_to_relationships }}

		// HasMany
		# {{ has_many_relationships }}
		
    // HasManyThrough
		# {{ has_many_through_relationships }}

}