Control Panel
- Disable Control Panel functionality
- Custom Icon for CP Nav Item
- Permissions
- Authorization
- Actions
- Scoping Control Panel Results
One of Runway’s core features is the Control Panel integration. Runway will create listing and publish form pages for each of your resources.
The Control Panel functionality is built to work in exactly the same way you’d expect with entries. You can set filters, define scopes and use custom actions.
Disable Control Panel functionality
Technically, you can’t fully disable Runway’s CP feature. However, what you can do is hide the Nav Item from the Control Panel.
1// config/runway.php2 3'resources' => [4 \App\Models\Order::class => [5 'name' => 'Orders',6 'hidden' => true,7 ],8],
Custom Icon for CP Nav Item
Runway has a rather generic icon for resources in the Control Panel Nav. Feel free to change this to something else that better suits your use case (in fact, I’d encourage it).
You can either provide the name of an existing icon packaged into Statamic Core or inline the SVG as a string.
1// config/runway.php 2 3'resources' => [ 4 \App\Models\Order::class => [ 5 'name' => 'Orders', 6 'listing' => [ 7 'cp_icon' => 'date', 8 ], 9 ],10],
Permissions
If you have other users who are not 'super users', you may wish to also give them permission to view/create/update specific resources.
Runway gives you granular control over which actions users can/cannot do for each of your resources.
Permission labels
You may customize permission labels by adding a resources/lang/{lang}/runway.php
file.
1// resources/lang/pt_BR/runway.php2 3'permissions' => [4 'create' => 'Criar :resource',5 'delete' => 'Excluir :resource',6 'edit' => 'Editar :resource',7 'view' => 'Visualizar :resource'8]
In the example above, :resource
will be replaced by the resource's name
.
Custom permissions
If you need to, you can add new permissions to the existing ones created by Runway:
1// app/Providers/AppServiceProvider.php 2 3public function boot() 4{ 5 Permission::group('Runway', function () { 6 foreach (Runway::allResources() as $resource) { 7 Permission::get("edit {$resource->handle()}")->addChild( 8 Permission::make("edit other owners {$resource->handle()}") 9 ->label(trans('runway.permissions.edit_other_owners_resource', [10 'resource' => $resource->name()11 ]))12 );13 }14 });15}
Authorization
If you need to, you can change how resource actions are authorized by extending and rebinding the ResourcePolicy
class.
1// app/Policies/ResourcePolicy.php 2 3<?php 4 5namespace App\Policies; 6 7use DoubleThreeDigital\Runway\Policies\ResourcePolicy as RunwayResourcePolicy; 8use Illuminate\Auth\Access\HandlesAuthorization; 9 10class ResourcePolicy extends RunwayResourcePolicy11{12 use HandlesAuthorization;13 14 public function edit($user, $resource)15 {16 // Do custom checks here before running the default ones17 18 // If custom checks didn't return, run default checks19 return parent::edit($user, $resource);20 }21}
1// app/Providers/AppServiceProvider.php 2 3<?php 4 5namespace App\Providers; 6 7use App\Policies\ResourcePolicy; 8use DoubleThreeDigital\Runway\Policies\ResourcePolicy as RunwayResourcePolicy; 9 10public function boot()11{12 $this->app->bind(RunwayResourcePolicy::class, ResourcePolicy::class);13}
Actions
Runway supports using Statamic Actions to preform tasks on your models.
You may register your own custom actions, as per the Statamic documentation. If you wish to only show an action on one of your models, you can filter it down in the visibleTo
method.
1use App\Models\Post;2 3class YourCustomAction extends Action4{5 public function visibleTo($item)6 {7 return $item instanceof Post;8 }9}
Scoping Control Panel Results
If you don't want to return everything, you may add a scope (runwayListing
) to limit the returned results.
1class YourModel extends Model2{3 public function scopeRunwayListing($query)4 {5 return $query->where('something', true);6 }7}
Scoping search results
On top of scoping your Control Panel results, you may also scope how Runway searches your models. To do this, you may specify a runwaySearch
scope.
1class YourModel extends Model2{3 public function scopeRunwaySearch($query, $searchString)4 {5 // Your own search logic6 }7}