Open delfinn55 opened 3 weeks ago
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> @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 @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
Bug report
What I did
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!
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: