Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CrudRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public function __construct($name, $controller, $options)
'as' => 'crud.'.$this->name.'.bulkClone',
'uses' => $this->controller.'@bulkClone',
]);

// catch-all route for custom operations
Route::any($this->name.'/do/{function}', $this->controller.'@callPublicFunction')
->where('function', '(.*)')
->name('crud.'.$this->name);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Backpack\CRUD\app\Http\Controllers;

use ReflectionMethod;
use Backpack\CRUD\CrudPanel;
use Illuminate\Http\Request;
use Illuminate\Foundation\Bus\DispatchesJobs;
Expand Down Expand Up @@ -47,6 +48,25 @@ public function __construct()
}
}

public function callPublicFunction(...$params)
{
$parameters = func_get_args()[0];
$httpVerb = \Request::method();
$input = \Request::input();
$functionName = explode('/', $parameters)[0];
$functionExists = method_exists($this, $functionName);
$functionIsPublic = false;

if ($functionExists) {
$reflection = new ReflectionMethod($this, $functionName);
$functionIsPublic = $reflection->isPublic();
}

if ($functionIsPublic) {
return $this->{$functionName}(...$params);
}
}

/**
* Allow developers to set their configuration options for a CrudPanel.
*/
Expand Down