Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change routes name #166

Open
thewebartisan7 opened this issue Jul 8, 2020 · 4 comments
Open

Change routes name #166

thewebartisan7 opened this issue Jul 8, 2020 · 4 comments

Comments

@thewebartisan7
Copy link

thewebartisan7 commented Jul 8, 2020

Is your feature request related to a problem? Please describe.

When I create a scaffold for a model name "Dummy", the route name are like:

'dummies.dummy.index'
'dummies.dummy.create'
etc...

Describe the solution you'd like

I think should be like:

'dummies.index'
'dummies.create'
etc...

Or am I missing something?

I run the following commands, without any customization of config or anything else:

php artisan resource-file:create Dummy --fields=id,name,description,folder,filename,is_active
php artisan create:scaffold Dummy --with-migration

Also since there is usage of group(), name base could be added like so:

Route::group([
    'prefix' => 'dummies',
    'name' => 'dummies.',
], function () {
    Route::get('/', 'DummiesController@index')
         ->name('index');
    Route::get('/', 'DummiesController@index')
         ->name('create');
//...etc...
});
@thewebartisan7
Copy link
Author

Another issue related to generated routes.
The regular expression constraints doesn't work since doesn't match the name of resource.

This:

    Route::get('/show/{dummies}','DummiesController@show')
         ->name('dummies.dummy.show')->where('id', '[0-9]+');

Should be:

    Route::get('/show/{dummies}','DummiesController@show')
         ->name('dummies.dummy.show')->where('dummies', '[0-9]+');

Or:

    Route::get('/show/{id}','DummiesController@show')
         ->name('dummies.dummy.show')->where('id', '[0-9]+');

Or just remove it and can be added globally in RouteServiceProvider:

    public function boot()
    {
        Route::pattern('id','[0-9]+');
    
        parent::boot();
    }

@thewebartisan7
Copy link
Author

I forgot one thing.

A simple solution could be also just single line for each resource like:

        Route::resource('dummies', 'DummiesController');

Also update, show and delete routes better to keep like standard param just after resource name.
Actually only "edit" follow this convention.
And "store" missing "store" at the end of url. And destroy rename to "delete"
So it's like generated routes of Route::resource()

Example:


    Route::get('/dummies/{dummy}/show/,'DummiesController@show')
         ->name('dummies.dummy.show');

    Route::get('/dummies/{dummy}/edit','DummiesController@edit')
         ->name('dummies.dummy.edit')->where('id', '[0-9]+');

    Route::post('/dummies/store', 'DummiesController@store')
         ->name('dummies.dummy.store');

    Route::put('dummy/{dummy}/update', 'DummiesController@update')
         ->name('dummies.dummy.update');

    Route::delete('/dummy/{dummy}/delete','DummiesController@delete')
         ->name('dummies.dummy.delete');

AjithLalps pushed a commit to AjithLalps/laravel-code-generator that referenced this issue Aug 27, 2020
@AjithLalps AjithLalps mentioned this issue Aug 27, 2020
@levyra
Copy link

levyra commented Feb 2, 2022

I could not find where to ask a question. It seems my implementation will not do deletes. Could you point me in the right direction?
crestapps/laravel-code-generator v2.4.7
v8.80.0 The Laravel Framework.

WEB.PHP
Route::delete('/country/{country}',[CountriesController::class, 'index'])
->name('countries.country.destroy')->where('id', '[0-9]+');

VIEW

{{ csrf_field() }}

CONTROLLER
public function update($id, Request $request)
{
try {

        $data = $this->getData($request);
        
        $country = Country::findOrFail($id);
        $country->update($data);

        return redirect()->route('countries.country.index')
            ->with('success_message', 'Country was successfully updated.');
    } catch (Exception $exception) {

        return back()->withInput()
            ->withErrors(['unexpected_error' => 'Unexpected error occurred while trying to process your request.']);
    }        
}

Thanks...

@MikeAlhayek
Copy link
Collaborator

Is there a benefit of changing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants