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

[POC] datatable as a component for multiple cruds #5688

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
pxpm committed Oct 11, 2024
commit 78891ab1cea48283b5f92406b0055c0cd48e8f51
2 changes: 1 addition & 1 deletion src/BackpackServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function register()
$this->registerBackpackErrorViews();

// Bind the CrudPanel object to Laravel's service container
$this->app->scoped('crud', function ($app) {
$this->app->bind('crud', function ($app) {
// loop the stack trace to find the CrudControllerContract that called this method
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$controller = null;
Expand Down
15 changes: 13 additions & 2 deletions src/app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class CrudController extends Controller implements CrudControllerContract
{
use DispatchesJobs, ValidatesRequests;

public $crud;
//public $crud;

public $data = [];

public function __construct()
Expand All @@ -44,7 +45,7 @@ public function __construct()

public function initializeCrud($request, $operation = null)
{
$this->crud = Backpack::crud($this)->setRequest($request);
Backpack::crud($this)->setRequest($request);
$this->setupDefaults();
$this->setup();
$this->setupConfigurationForCurrentOperation($operation);
Expand Down Expand Up @@ -127,4 +128,14 @@ protected function setupConfigurationForCurrentOperation(?string $operation = nu
$this->{$setupClassName}();
}
}

public function __get($name)
{
if ($name == 'crud') {
return Backpack::getControllerCrud(get_class($this));
}

return $this->{$name};
}

}
8 changes: 5 additions & 3 deletions src/app/Library/CrudPanel/CrudButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Backpack\CRUD\app\Library\CrudPanel;

use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\Backpack;
use Backpack\CRUD\ViewNamespaces;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Traits\Conditionable;
Expand Down Expand Up @@ -297,10 +299,10 @@ public function section($stack)
* @param object|null $entry The eloquent Model for the current entry or null if no current entry.
* @return \Illuminate\Contracts\View\View
*/
public function getHtml($entry = null)
public function getHtml($entry = null, $crud = null)
{
$button = $this;
$crud = $this->crud();
$crud = $crud ?? $this->crud();

if ($this->type == 'model_function') {
if (is_null($entry)) {
Expand Down Expand Up @@ -434,7 +436,7 @@ public function collection()
/**
* Access the global CrudPanel object.
*
* @return \Backpack\CRUD\app\Library\CrudPanel\CrudPanel
* @return CrudPanel
*/
public function crud()
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/crud/inc/button_stack.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@if ($crud->buttons()->where('stack', $stack)->count())
@foreach ($crud->buttons()->where('stack', $stack) as $button)
{!! $button->getHtml($entry ?? null) !!}
{!! $button->getHtml($entry ?? null, $crud) !!}
@endforeach
@endif
Loading