Skip to content

Commit 348a8fd

Browse files
authored
Add info about routes to plugin docs (#188)
* add info about routes to plugin docs * small fix
1 parent 804b8e4 commit 348a8fd

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/panel/advanced/plugins.mdx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,34 @@ This means you need to prefix view-strings with your plugin id, e.g. `myplugin::
207207
If present, a seeder with the name of your plugin will be automatically registered. It needs to be named `<plugin name>Seeder` (e.g. `MyPluginSeeder`) and put inside your plugins `database/Seeder` folder, e.g. `plugins/myplugin/database/Seeder/MyPluginSeeder.php`.
208208
This seeder will be automatically called when a user installs the plugin or when seeders are run in general, e.g. when using `php artisan db:seed` or `php artisan migrate --seed`.
209209

210+
### Routes
211+
212+
Routes need to be registered in a `RouteServiceProvider`. Example:
213+
214+
```php
215+
use Illuminate\Foundation\Support\Providers\RouteServiceProvider;
216+
217+
class MyPluginRoutesProvider extends RouteServiceProvider
218+
{
219+
public function boot(): void
220+
{
221+
$this->routes(function () {
222+
// Single new endpoint with Controller
223+
Route::get('test', [TestController::class, 'test'])->name('my-plugin.test');
224+
225+
// Load routes from file
226+
Route::prefix('/my-plugin')->group(plugin_path('my-plugin', 'routes/web.php'));
227+
228+
// Add routes from file to existing client api
229+
Route::middleware(['api', 'client-api', 'throttle:api.client'])
230+
->prefix('/api/client')
231+
->scopeBindings()
232+
->group(plugin_path('my-plugin', 'routes/api-client.php'));
233+
});
234+
}
235+
}
236+
```
237+
210238
### Plugin Settings
211239

212240
Your main plugin class can implement the `HasPluginSettings` interface to conveniently add a settings page to your plugin.
@@ -342,4 +370,4 @@ And that's it! Now you can take the zip file and share it with the world!
342370
<Admonition type="info" title="License">
343371
You can license your plugin code under whatever license you want. You do not have to use the same license as the panel!
344372
You also don't have to open source your plugin code. But if you do want to open source it we recommend [MIT](https://choosealicense.com/licenses/mit) or [GPL v3](https://choosealicense.com/licenses/gpl-3.0) as license.
345-
</Admonition>
373+
</Admonition>

0 commit comments

Comments
 (0)