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

[5.5] Fluent resource options #18767

Merged
merged 8 commits into from
Apr 18, 2017
Merged

[5.5] Fluent resource options #18767

merged 8 commits into from
Apr 18, 2017

Conversation

jaripekkala
Copy link
Contributor

Discussed in laravel/ideas#412
Previous PR #18393

Allows defining resource options fluently.

https://laravel.com/docs/master/controllers#resource-controllers


Partial Resource Routes

Route::resource('users', 'UserController')->only('index', 'show')

Route::resource('comments', 'CommentController')->except([
    'index', 'create', 'edit'
]);

Resource Middleware

Not in docs?

Route::resource('posts', 'PostController')->middleware(AuthMiddleware::class);

Naming Resource Routes

Route::resource('persons', 'PersonController')->names([
    'create'  => 'persons.make',
    'destroy' => 'persons.delete',
]);

Route::resource('customers', 'CustomerController')->name('store', 'make');

Naming Resource Route Parameters

Route::resource('users', 'UserController')->parameters([
    'users' => 'admin_users',
]);

Route::resource('profiles', 'ProfileController')->parameter('profiles', 'users');

Method chaining is of course allowed.

Route::resource('avatars', 'AvatarController')
     ->only('index', 'show')
     ->name('index', 'avatars.all');

@jaripekkala jaripekkala changed the title [5.5] Fluent partial resource routes [5.5] Fluent resource options Apr 11, 2017
@lagbox
Copy link
Contributor

lagbox commented Apr 15, 2017

Love it :-)

Might there be the option to add a __call to this, to allow dynamic 'options' fluently?

Route::resource(....)->slug(true);
//
$this->options['slug'] = true;

I use custom resource registrars and have many options I might be checking in them.

@jaripekkala
Copy link
Contributor Author

There should then be some option existing checking for easier debugging.

Route::resource('users')->expect('index', 'show');

Actually would it be better only use __call method instead of specifying one for each option?

Rename method name to rename? Makes more sense to me. Or do we even need these aliases/shortcuts (name, parameter)?

@taylorotwell taylorotwell merged commit 398e3f2 into laravel:master Apr 18, 2017
@lagbox
Copy link
Contributor

lagbox commented Apr 18, 2017

@Salomoni it could nearly extend fluent and inherit that functionality, but you would lose your func_get_args. It works as is :-). I will put a PR in for __call later when I am around.

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

Successfully merging this pull request may close these issues.

None yet

3 participants