# HG changeset patch # User Luka Sitas # Date 1748915469 14400 # Node ID b17f81b804ff5f5c2890e7cc6ee3af115b4aa0f8 # Parent 555bfaa500ac600f310943a3bdad3693ee68981c Added support for routes diff -r 555bfaa500ac -r b17f81b804ff src/Generator/Controller/stubs/controller.stub --- a/src/Generator/Controller/stubs/controller.stub Thu May 15 21:50:38 2025 -0400 +++ b/src/Generator/Controller/stubs/controller.stub Mon Jun 02 21:51:09 2025 -0400 @@ -65,6 +65,17 @@ return view('{{ tableName }}.show', $data); } + /** + * Returns the resource in JSON format. + * + * @param ModelType $modelVariable + * @return string + */ + public function load({{ model }} ${{ modelVariable }}) + { + return ${{ modelVariable }}->toJson(); + } + /** * Show the form for editing the specified resource. * diff -r 555bfaa500ac -r b17f81b804ff src/Generator/Model/stubs/model.pivot.stub --- a/src/Generator/Model/stubs/model.pivot.stub Thu May 15 21:50:38 2025 -0400 +++ b/src/Generator/Model/stubs/model.pivot.stub Mon Jun 02 21:51:09 2025 -0400 @@ -16,6 +16,10 @@ */ public $timestamps = false; + protected $default_relations = [ + # {{ defaultRelationsInsertPoint }} + ]; + //relations @@ -28,4 +32,74 @@ // HasManyThrough # {{ has_many_through_relationships }} + /** + * Load the default relations for the model. + * + * @return $this + */ + public function load_relations() { + foreach($this->default_relations as $relation) { + $this->load($relation); + } + return $this; + } + + //MARK FOR MODEL + protected static function load_auxilary_data() { + $data = []; + + $instance = new static(); + + foreach($instance->default_relations as $relation) { + $related_model = $instance->$relation()->getRelated(); + $related_table = $related_model->getTable(); + $data[$related_table] = $related_model->all()->pluck('name','id')->toArray(); + } + + return $data; + } + + //MARK FOR MODEL + public static function load_index() { + return static::load_auxilary_data(); + } + + //MARK FOR MODEL + public static function load_create() { + return static::load_auxilary_data(); + } + + //MARK FOR MODEL + public static function load_edit() { + return static::load_auxilary_data(); + } + + + /** + * Retrieve a query builder instance with default relations loaded. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + //MARK FOR MODEL + public static function data_query() { + $query = static::query(); + + $instance = new static(); + + foreach($instance->default_relations as $relation) { + $query->with($relation); + } + + return $query; + } + + /** + * Retrieve a query builder instance with default relations loaded. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function get_data() + { + return static::data_query()->get(); + } } diff -r 555bfaa500ac -r b17f81b804ff src/Generator/Route/stubs/route.stub --- a/src/Generator/Route/stubs/route.stub Thu May 15 21:50:38 2025 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -prefix('{{ tableName }}') - ->alias('{{ tableName }}.') - ->group( function () { - Route::get('/', 'index')->name('index'); - Route::get('/create', 'create')->name('create'); - Route::get('/edit', 'edit')->name('edit'); - - Route::post('/store', 'store')->name('store'); - Route::put('/udpate/{id}', 'update')->name('update'); - Route::delete('/delete/{id}', 'delete')->name('delete'); - }); diff -r 555bfaa500ac -r b17f81b804ff src/Generator/Route/stubs/routes.stub --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Route/stubs/routes.stub Mon Jun 02 21:51:09 2025 -0400 @@ -0,0 +1,18 @@ +middleware(['web','auth']) + ->prefix('{{ tableName }}') + ->as('{{ tableName }}.') + ->group( function () { + Route::get('/', 'index')->name('index'); + Route::get('/create', 'create')->name('create'); + Route::get('/{ticket}/edit', 'edit')->name('edit'); + Route::get('/{ticket}', 'show')->name('show'); + Route::get('/{ticket}/load', 'load')->name('load'); + + Route::post('/store', 'store')->name('store'); + Route::put('/udpate/{{{ modelVariable }}}', 'update')->name('update'); + Route::delete('/destory/{{{ modelVariable }}}', 'destory')->name('destory'); + }); diff -r 555bfaa500ac -r b17f81b804ff src/Replacer/Replacer.php --- a/src/Replacer/Replacer.php Thu May 15 21:50:38 2025 -0400 +++ b/src/Replacer/Replacer.php Mon Jun 02 21:51:09 2025 -0400 @@ -138,6 +138,16 @@ { return ''; } + + + /** + * Generate route name in Studly case. + */ + public function routes_name(string $name): string + { + return Str::singular(Str::studly($name)); + } + // Namespace Methods // These methods handle the formation of various namespaces used within the replacements. @@ -152,6 +162,17 @@ /** * Get the model namespace. */ + public function getRouteNamespace(string $name = ''): string + { + return base_path() + . DIRECTORY_SEPARATOR . 'routes' + . DIRECTORY_SEPARATOR . 'resources' + ; + } + + /** + * Get the model namespace. + */ public function getModelNamespace(string $name = ''): string { return $this->getRootNamespace().'Models';