CRUD
CRUD copied to clipboard
[Bug] If no one standard operation in the traits list then 'line' stack doesn't appear
Bug report
What I did
- I have only single standard operation for my CRUD -> ListOperation
- I created new custom operation "Operations\Lots\DeleteMaxBidsOperation"
- I add the button:
protected function setupDeleteMaxBidsDefaults()
{
CRUD::operation('list', function () {
CRUD::addButton(
'line',
'customer_bids_delete',
'view',
'crud::buttons.customer-bids.delete',
);
});
}
What I expected to happen
My button will appear in 'line' stack.
What happened
'Line' stack doesn't appear.
What I've already tried to fix it
I have copied the code from UpdateOperation and put it near with my button registration. Magic!
protected function setupDeleteMaxBidsDefaults()
{
CRUD::operation('list', function () {
CRUD::addButton('line', 'update', 'view', 'crud::buttons.delete', 'end');
CRUD::addButton(
'line',
'customer_bids_delete',
'view',
'crud::buttons.customer-bids.delete',
);
});
}
Is it a bug in the latest version of Backpack?
After I run composer update backpack/crud the bug is it still there.
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version the output is:
### PHP VERSION:
8.1.28
### PHP EXTENSIONS:
Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dba, dom, hash, FFI, fileinfo, filter, ftp, gd, gettext, gmp, json, iconv, intl, SPL, ldap, mbstring, session, standard, odbc, pcntl, exif, mysqlnd, PDO, pdo_dblib, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, pspell, readline, Reflection, mysqli, shmop, SimpleXML, soap, sockets, sodium, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, xml, xmlreader, xmlwriter, xsl, zip, xdebug, Zend OPcache
### LARAVEL VERSION:
10.48.7.0
### BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.2.1
backpack/crud: 6.7.15
backpack/devtools: 2.0.3
backpack/editable-columns: 3.0.9
backpack/filemanager: 3.0.4
backpack/generators: v4.0.2
backpack/langfilemanager: 5.0.0
backpack/logmanager: v5.0.1
backpack/permissionmanager: 7.0.1
backpack/pro: 2.2.0
backpack/settings: 3.1.0
backpack/theme-tabler: 1.1.1
Hello @delfinn55
At the top of the button you created, are you checking for access to that button? Similar to what we have in our buttons ?
@if ($crud->hasAccess('delete', $entry))
<a href="javascript:void(0)" onclick="deleteEntry(this)" data-route="{{ url($crud->route.'/'.$entry->getKey()) }}" class="btn btn-sm btn-link" data-button-type="delete">
<span><i class="la la-trash"></i> {{ trans('backpack::crud.delete') }}</span>
</a>
@endif
In case you do, and it's something similar to: @if ($crud->hasAccess('customer_bid_delete', $entry)), you need to add into your custom operation setup defaults: CRUD::allowAccess('customer_bid_delete') .
Is that the problem here? Let me know.
Cheers
Hello @delfinn55
At the top of the button you created, are you checking for access to that button? Similar to what we have in our buttons ?
@if ($crud->hasAccess('delete', $entry)) <a href="javascript:void(0)" onclick="deleteEntry(this)" data-route="{{ url($crud->route.'/'.$entry->getKey()) }}" class="btn btn-sm btn-link" data-button-type="delete"> <span><i class="la la-trash"></i> {{ trans('backpack::crud.delete') }}</span> </a> @endifIn case you do, and it's something similar to:
@if ($crud->hasAccess('customer_bid_delete', $entry)), you need to add into your custom operation setup defaults:CRUD::allowAccess('customer_bid_delete').Is that the problem here? Let me know.
Cheers
Hello @pxpm!
I checked it. But even if I cut @if() condition in template, it is not working.
There are listings:
Button
@if (backpack_user()->can('max_bids.delete'))
<a
class="btn btn-sm btn-link"
href="javascript:void(0)"
onclick="deleteCustomerBids(this)"
data-lot-id="{{ $entry->id }}"
data-route="{{ route('customer-bid.deleteCustomerBids', [
'customer_id' => (int) Route::current()->parameter('customer_id')
]) }}"
>
<i class="la la-trash"></i> Delete bids
</a>
@endif
Operation
<?php
namespace App\Http\Controllers\Admin\Operations\Lots;
use App\Models\Lot;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
trait DeleteCustomerBidsOperation
{
/**
* Define which routes are needed for this operation.
*
* @param string $segment Name of the current entity (singular). Used as first URL segment.
* @param string $routeName Prefix of the route name.
* @param string $controller Name of the current CrudController.
*/
protected function setupCustomerBidsRoutes($segment, $routeName, $controller)
{
Route::post($segment.'/delete-customer-bids', [
'as' => $routeName.'.deleteCustomerBids',
'uses' => $controller.'@deleteCustomerBids',
'operation' => 'deleteCustomerBids',
]);
}
/**
* Add the default settings, buttons, etc that this operation needs.
*/
protected function setupCustomerBidsDefaults()
{
CRUD::allowAccess('deleteCustomerBids');
CRUD::operation('deleteCustomerBids', function () {
CRUD::loadDefaultOperationSettingsFromConfig();
});
CRUD::operation('list', function () {
// TODO: https://github.com/Laravel-Backpack/CRUD/issues/5539
// CRUD::addButton('line', 'update', 'view', 'crud::buttons.delete', 'end');
CRUD::addButton(
'line',
'delete_customer_bids',
'view',
'crud::buttons.customer-bids.delete',
);
});
}
/**
* Show the view for performing the operation.
*
* @return \Illuminate\Http\JsonResponse
*/
public function deleteCustomerBids(Request $request)
{
CRUD::hasAccessOrFail('deleteCustomerBids');
$userId = (int) Route::current()->parameter('customer_id');
$lot = Lot::find($request->input('lot_id'));
if ($lot) {
foreach ($lot->maxBids->where('user_id', $userId) as $maxBid) {
// Not together because need to run bid 'deleted' handlers
$maxBid->delete();
}
}
return response()->json([
'success' => true,
]);
}
}
Hello @delfinn55
Is your button in resources/views/vendor/backpack/crud/buttons/customer-bids/delete.blade.php ? Does backpack_user()->can('max_bids.delete') return true ?
Could it be the order of the operations ? Are you adding the ListOperation trait before your custom trait ?
Cheers
Is your button in
resources/views/vendor/backpack/crud/buttons/customer-bids/delete.blade.php?
Yes. It works if I use any standard line operation or uncomment CRUD::addButton('line', 'update', 'view', 'crud::buttons.delete', 'end'); in DeleteCustomerBidsOperation trait.
Does
backpack_user()->can('max_bids.delete')return true ?
Condition backpack_user()->can('max_bids.delete') no matter, because it doesn't work even I remove this condition.
Could it be the order of the operations ? Are you adding the ListOperation trait before your custom trait ?
Hey @delfinn55
That App\Traits\Admin\CrudListActions; caught my eye as it seems to mess with those buttons.
Can the problem be there ?
I don't seem to be able to reproduce your issue, so I am assuming it's something on your custom code.
Cheers
Closing this due to inactivity.
Please let me know if I can help you with something else @delfinn55 🙏
Cheers