stratboy's avatar

How to change Route's resource verbs only for, or based on, specific resources?

Hi, I changed some verbs, thinking about a specific resource (Seed). An I didn't wrote 'localized' because I did not literally translated them, I wanted to use a different verb for 'create' that in Italian means 'share':

        Route::resourceVerbs([
            'create' => 'condividi',
            'edit' => 'modifica',
        ]);

But now I'd like to use different verbs for another resoure (Conversations). Is that possible?

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, it is possible to use different verbs for different resources in Laravel. You can achieve this by setting the resource verbs specifically for each resource route definition. Instead of using the global Route::resourceVerbs method, you can define the verbs directly within the Route::resource method for each resource.

Here's how you can do it:

  1. Define the custom verbs for the Seed resource.
  2. Define the custom verbs for the Conversations resource.

Here is an example:

use Illuminate\Support\Facades\Route;

// Custom verbs for the Seed resource
Route::resource('seeds', 'SeedController')->names([
    'create' => 'seeds.condividi',
    'edit' => 'seeds.modifica',
]);

// Custom verbs for the Conversations resource
Route::resource('conversations', 'ConversationController')->names([
    'create' => 'conversations.crea',
    'edit' => 'conversations.modifica',
]);

In this example:

  • For the Seed resource, the create verb is changed to condividi and the edit verb is changed to modifica.
  • For the Conversations resource, the create verb is changed to crea and the edit verb is changed to modifica.

This way, you can have different verbs for different resources without affecting the global settings.

Please or to participate in this conversation.