Skip to content

Instantly share code, notes, and snippets.

View pxpm's full-sized avatar
🏠
Working from home

Pedro Martins pxpm

🏠
Working from home
  • Portugal
View GitHub Profile
@pxpm
pxpm / coverage badge
Created November 22, 2022 18:37
coverage badge
Coverage Badge
@pxpm
pxpm / gist:5dffa635c5d9d16c4c9942813a195c6d
Created June 22, 2022 15:03
toggle field with JS API support
<!-- Toggle Field for Backpack for Laravel -->
{{--
Author: Adoptavia
Website: https://github.com/adoptavia
Addon: https://github.com/digitallyhappy/toggle-field-for-backpack
--}}
@include('crud::fields.inc.wrapper_start')
@include('crud::fields.inc.translatable_icon')
<div class="checkbox">
@pxpm
pxpm / App\Http\Controllers\PostCrudController
Created October 8, 2021 22:41
Backpack 4.1 morphToMany relation
<?php
namespace App\Http\Controllers;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
class PostCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; } //IMPORTANT HERE
@pxpm
pxpm / App\Http\Controllers\ArticleCrudController
Created October 8, 2021 22:06
Backpack 4.1 morphMany relation
<?php
namespace App\Http\Controllers;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
class ArticleCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
@pxpm
pxpm / App\Http\Controllers\UserCrudController
Last active October 11, 2021 12:25
Backpack 4.1 morphOne relation
<?php
namespace App\Http\Controllers;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
class UserCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
@pxpm
pxpm / App\Http\Controllers\UserCrudController
Last active January 20, 2022 17:24
Backpack 4.1 BelongsToMany with pivot data
<?php
namespace App\Http\Controllers;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
class UserCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
@pxpm
pxpm / App\Http\Controllers\PostCrudController
Last active August 5, 2022 04:07
Backpack 4.1 HasMany relation
<?php
namespace App\Http\Controllers;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
class PostCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; } //IMPORTANT HERE
<!-- checklist -->
@php
$model = new $field['model'];
$key_attribute = $model->getKeyName();
$identifiable_attribute = $field['attribute'];
// calculate the checklist options
if (!isset($field['options'])) {
$field['options'] = $field['model']::all()->pluck($identifiable_attribute, $key_attribute)->toArray();
} else {
@pxpm
pxpm / select2_multiple.blade.php
Created November 28, 2019 21:20
BACKPACK SORTABLE SELECT2 MULTIPLE
<!-- select2 multiple -->
@php
if (!isset($field['options'])) {
$options = $field['model']::all();
} else {
$options = call_user_func($field['options'], $field['model']::query());
}
$multiple = isset($field['multiple']) && $field['multiple']===false ? '': 'multiple';
@endphp