laravel-backpack / crud Goto Github PK
View Code? Open in Web Editor NEWBuild custom admin panels. Fast!
Home Page: https://backpackforlaravel.com
License: MIT License
Build custom admin panels. Fast!
Home Page: https://backpackforlaravel.com
License: MIT License
@FarhadMohammadi and a few others have asked about Backpack working on Laravel 5.1.
I haven't actually given any thought to making it work on Laravel 5.1, since I believe the LTS tag is BS - I have projects with 5.1 bugs that still have not been fixed, though reported, but upgrading to Laravel 5.2 fixes them.
I guess the only difference to make it work on 5.1 would be Middleware Groups.
I personally have no need for Backpack to work on Laravel 5.1, so there's no immediate plan to support it, but if someone puts in the effort, I'm more than happy to help and merge it.
Right now a lot of field types have the same template, but only the type="text | date | email "
is different.
If you want to change the layout of the fields, you need to override a lot of templates (for example if you want a .form-horizontal).
What about something like this:
$fields = new FieldList(
new EmailField('email', 'Email'),
new DropdownField('status', 'Status', ['yes', 'no']),
new TextField('name', 'Name') // 'Name' optional, so it will be taken from 'name'
);
instead of
$fields = [
[
'type' => 'email',
'label' => 'Email',
'name' => 'email',
],
[
'type' => 'select',
'label' => 'Status',
'name' => 'status',
'options' => ['yes', 'no']
],
[
'type' => 'text',
'label' => 'Name',
'name' => 'name',
]
];
For the EmailField you don't need a seperate template and the API for the Dropdown Field is perfeclty clear without need to refer to documenation when you have something like this (quick boiler plating) :
class DropdownField extends FormField
{
protected $options = [];
protected $type = 'select';
public function __construct($name, $label, $options)
{
$this->options = $options;
parent::__construct($name, $label);
}
}
class EmailField extends TextField
{
protected $type = 'email';
}
class TextField extends FormField
{
public function view()
{
return view('fields.' . $this->template, ['field' => $this]);
}
}
abstract class FormField
{
protected $name;
protected $label;
protected $attributes = [];
protected $classes = [
'holder' => ['form-group'],
'label' => ['control-label'],
'field' => ['form-control'],
];
protected $template = 'text';
protected $type = 'text';
public function __construct($name, $label)
{
$this->name = $name;
$this->label = $label;
}
public function setAttribute($attr, $value)
{
$this->attributesp[$attr] = $value;
return $this;
}
public function addClass($class, $target = 'field') // ? field and holder?
{
$this->classes[$target][] = $class;
return $this;
}
You should be able to choose the default number of rows on a given CRUD panel. This is easily done by adding "pageLength": 50,
to list.blade.php
when the DataTable is instantiated.
Proposed syntax:
$this->crud->setDefaultListSize(50);
Hello
i need to make input file to upload image file and save file name to database table
i need to rename file name before save the file name in DB
any suggestions?
Thank you in advance
When opening elFinder from CKeditor, this theme would help visual cohesion: https://github.com/lokothodida/elfinder-theme-moono
In the future, I foresee the need of checkboxes in the first table column and having bulk buttons at the top/bottom of the table, for bulk actions.
This is the proposed syntax for that:
$this->crud->addBulkButton('name', 'url_to_send_a_post_request_with_their_ids');
$this->crud->setBulkButtonsOrder(['send_email', 'delete']);
Any better solutions?
I am getting 404 error with below message when clicked on browse option to upload image. What's the reason ?
The requested URL /admin/elfinder/popup/image-filemanager was not found on this server.
Developers should be able to add custom buttons. Proposed syntax:
$this->crud->addButton('button_name', 'model_function_name');
// by default this will place the button before edit and delete
// ex: $this->crud->addButton('send_email', 'getSendEmailButton');
// other methods:
$this->crud->removeButton('send_email');
$this->crud->setButtonsOrder(['edit', 'send_email', 'delete']);
This way, I think, we'll leave a lot of space for customization. On your model, you could do something like:
public function getSendEmailButton() {
return "<a class='btn btn-warning' href='some_link'><i class='fa fa-envelope'> Send email</a>";
}
and you can have your checks or complex logic there. Ex:
What I don't like about this is that it does imply you'll be writing some HTML in the model, which is a bit ugly... What do you think? Any better solutions?
Note: I also see the need for custom bulk buttons in the future. But that's another topic.
Maybe errors should be placed inline, for each field, while highlighting it. The register form already has a standard implementation of this:
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">{{ trans('backpack::base.name') }}</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
That way:
An image thumbnail colum should be easy to do.
Allow developer to customize:
Click on image should open image in a new tab.
We could make thumbs using Glide: https://packagist.org/packages/league/glide
Any alternatives in mind?
One thing we could do to speed up development is NOT going to the documentation website every time we need the syntax for a certain field type.
A SublimeText plugin/collection of snippets will solve that problem for me. Here's the syntax I have in mind:
crud.addField.select_multiple
=>
$this->crud->addField([ // SelectMultiple = n-n relationship (with pivot table)
'label' => "Tags",
'type' => 'select_multiple',
'name' => 'tags', // the method that defines the relationship in your Model
'entity' => 'tags', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "App\Models\Tag", // foreign key model
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
]);
I'm thinking an alternative shorter syntax will also be available:
crud.af.select_multiple
What I want from the syntax is for it to still read the same as the code you want to write, so it will be easy to remember:
Using the crud prefix would allow us to also do things like:
// addColumn
crud.ac.column_type => [column definition]
// removeColumn
crud.rc => $this->crud->removeColumn('column_name');
// removeField
crud.rf => $this->crud->removeField('name', 'update/create/both);
// allowAccess
crud.aa => $this->crud->allowAccess(['list', 'create', 'update', 'reorder', 'delete']);
// denyAccess
crud.da => $this->crud->denyAccess(['list', 'create', 'update', 'reorder', 'delete']);
// enableDetailsRow
crud.edr =>
$this->crud->enableDetailsRow();
$this->crud->allowAccess('details_row');
// NOTE: you also need to do overwrite the showDetailsRow($id) method in your EntityCrudController to show whatever you'd like in the details row OR overwrite the views/backpack/crud/details_row.blade.php
// addClause
crud.addClause => $this->crud->addClause('where', 'name', '==', 'car');
Any thoughts / improvements?
@AurelDragut made an interesting suggestion: at some point, we'll definitely need to filter the results in these 1-n and n-n fields.
Say:
I see one way to do this right now:
But... it's not pretty... Should we do something about this? What better ways do you see to solve this?
Thanks, cheers!
What about translatable fields?
In my own project I use https://github.com/spatie/laravel-translatable and create new field with tabs for each language.
When editing an entry my old($field['name'])
is null and my $key happens to be 0 so the gets marked as selected even though it shouldn't be.
Take a look at https://github.com/Laravel-Backpack/crud/blob/master/src/resources/views/fields/select_from_array.blade.php#L21
I could change my keys for the array so I am not using 0, but would rather not have to.
Aurel Drăguţ came with a great idea in order to allow developers to build 2-column layouts, 3-column layouts, etc in their forms.
Just by allowing the developer to place an extra class on the parent form element
<div class='form-group'>
we would be able to easily build panels that look like this:
This would imply a certain syntax change, so the change should come at the same with @cristiantone 's proposition to separate the HTML attributes sent to the input/textarea/select/etc.
Here's the new proposed syntax for the "text" field type:
$this->crud->addFields([
// mandatory
'name' => 'name',
'type' => 'text',
'label' => 'Name',
// optional
'optionalAttributes' => [
'disabled' => 'disabled',
'style' => 'border: 1px solid red',
...
],
'parentAttributes' => [
'class' => 'col-md-6',
'style' => 'border-top: 1px solid #eee; margin-top: 10px;'
]
]);
@Ghitu , @cristiantone , @mariusconstantin2503 , what do you think?
Hi, I use eloquent attribute casting and I have
protected $casts = [ 'mentions' => 'array', ];
in my model. It causes
ErrorException in 90d0d21803ea756d9c9e49ba82191f0eef2d2e2d.php line 97: strip_tags() expects parameter 1 to be string, array given (View: ......\vendor\backpack\crud\src\resources\views\list.blade.php)
error when I hit the admin/somecrudpage .If I remove $casts, there is no problem. So, I think Backpack/Crud needs to support eloquent attribute casting.
I will be happy if you help me to makeshift for this issue because I have a project to done. Or I prefer if you commit for solving this problem :)
The class has become way too big. Let's split it up. Look at the cohesion graph:
I'd say it's ok to split it in:
Any better ideas?
A column for booleans, which shows a checkbox favicon, checked or not, depending on the value.
Should use the included font awesome.
Ref #61
In the create form, when a user chooses to "let me add another item" at the end of the form, don't only redirect him to the create form, also make sure this time the "let me add another item" radio is checked, because most of the time that's what he'll want.
This can be done in two ways:
I tend to think option no 2 is better.
This enhancement, combined with #72 and #71 will greatly improve the create form usability.
There's no reason why the column types should be limited to what the CRUD provides.
The programmer should be allowed to define his own column type.
I may be missing something, but it looks like the crud library does not take in to account a defined $primaryKey = 'my_id'; in your models?
Looking in list.blade.php and some other areas I see items like {{ Request::url().'/'.$entry->id }} that seem fixed to the 'id' convention.
Hello!
am trying to use this package but it does not support edit like grocery crud
there are not Callbacks of after ,before insert,update ,delete etc
i tryed for example to rename file for elfinder but i can not i have been searching for 4-5 days
even i tried to make custom field image but with no luck
there's no callback available to make more control of coding
please try to add callback or we wont be able to edit or change code for our needs
thank you in advance
{"a":1,"b":2,"c":3,"d":4,"e":5}
;================= [ - remove ]
================= [ - remove ]
================= [ - remove ]
[ + add new item ]
It would work GREAT with the new 'array' column type.
Possible issues:
Use Algolia Places or Google Maps:
I have an Article model that have an author field (user_id).
In my ArticleCrudController, I add the followed field:
$this->crud->addField([
'label' => 'Author
'type' => 'select2',
'name' => 'user_id',
'entity' => 'user',
'attribute' => 'name',
'model' => User::class
], 'both');
It works fine on create view, but completely not on edit view.
Instead of my select2 field, I see a number field, and it's broken because of this error:
htmlentities() expects parameter 1 to be string, array given.
Located in number.blade.php
.
Pretty date/datetime columns should be easier to do. Having column types for that will make it so.
We should use the jenssegers/date package, so dates are automatically translated to the admin panel language.
The should also have the datatables-specific attribute, which allows accurate sorting of formatted dates.
Make this work:
$this->crud->setColumnOrder(['column_1', 'column_2', 'column_3']);
The sorting functionality in the Crud.php file does not work.
Also, I don't think the $crud->sort property makes no sense now.
The sorting should just shuffle the arrays where they are, without storing the order anywhere.
A few resources to help people get started / quickly create new files. Those resources should be stored in the plugin and published with the "demo" tag.
// publish demo resources:
// - Auto Models: Article, Category, Tag
// - Auto Requests: Article, Category, Tag
// - Auto Controllers: Crud/ArticleController, Crud/CategoryController, Crud/TagController
// - MANUAL routes
// - MANUAL migration for those entities
Right now the setup of form fields is array based.
I think this will be limiting, since it is hard to customize form fields or add app specific logic and layout to how form (fields) look and work.
I thinks this is a well maintained form package :
https://github.com/adamwathan/form
For the rest of this BackPack idea: I think its great!
QueryException in Connection.php line 713:
SQLSTATE[HY000]: General error: 1 near "SHOW": syntax error (SQL: SHOW COLUMNS FROM tags)
change line DB::raw('SHOW COLUMNS FROM in
/vendor/backpack/crud/src/PanelTraits/AutoSet.php and /vendor/backpack/crud/src/CrudTrait.php with
Schema::hasColumn( string $table, string $column)
all shema method please refer to documentation /Illuminate/Database/Schema/Builder
thank you
I want to translate Datatable to Lao, so i duplicated "resources/lang/vendor/backpack/en" to "lo", i can translate:
// Create form
'add' => 'ເພີ່ມ',
'back_to_all' => 'ກັບຄືນສູ່ລາຍການ ',
'cancel' => 'ຍົກເລີກ',
'add_a_new' => 'ເພີ່ມ ',
// Create form - advanced options
'after_saving' => 'ຫຼັງຈາກບັນທຶກ',
'go_to_the_table_view' => 'ໄປທີ່ລາຍການທັງໝົດ',
'let_me_add_another_item' => 'ເພີ່ມລາຍການໃໝ່ອີກ',
'edit_the_new_item' => 'ແກ້ໄຂລາຍການທີ່ເພີ່ມ',
// Edit form
'edit' => 'ແກ້ໄຂ',
'save' => 'ບັນທຶກ',
but below comment "// DataTables translation" are not effected, it is still show in English
Please help, Thanks
I have the followings in my composer.json
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"backpack/base": "^0.6.6",
"backpack/crud": "^3.0.0",
"backpack/generators": "^1.1",
"backpack/langfilemanager": "^1.0",
"backpack/backupmanager": "^1.1",
"backpack/settings": "^2.0",
"backpack/pagemanager": "^1.0"
},
And I run composer update
, then I get the following errors.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- backpack/settings 2.0.5 requires backpack/crud 2.* -> satisfiable by backpack/crud[2.0.0, 2.0.1, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.0.15, 2.0.16, 2.0.17, 2.0.18, 2.0.19, 2.0.2, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 2.0.24, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, v2.x-dev] but these conflict with your requirements or minimum-stability.
- backpack/settings 2.0.4 requires backpack/crud 2.* -> satisfiable by backpack/crud[2.0.0, 2.0.1, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.0.15, 2.0.16, 2.0.17, 2.0.18, 2.0.19, 2.0.2, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 2.0.24, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, v2.x-dev] but these conflict with your requirements or minimum-stability.
- backpack/settings 2.0.3 requires backpack/crud 2.* -> satisfiable by backpack/crud[2.0.0, 2.0.1, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.0.15, 2.0.16, 2.0.17, 2.0.18, 2.0.19, 2.0.2, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 2.0.24, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, v2.x-dev] but these conflict with your requirements or minimum-stability.
- backpack/settings 2.0.2 requires backpack/crud 2.* -> satisfiable by backpack/crud[2.0.0, 2.0.1, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.0.15, 2.0.16, 2.0.17, 2.0.18, 2.0.19, 2.0.2, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 2.0.24, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, v2.x-dev] but these conflict with your requirements or minimum-stability.
- backpack/settings 2.0.1 requires backpack/crud 2.* -> satisfiable by backpack/crud[2.0.0, 2.0.1, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.0.15, 2.0.16, 2.0.17, 2.0.18, 2.0.19, 2.0.2, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 2.0.24, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, v2.x-dev] but these conflict with your requirements or minimum-stability.
- backpack/settings 2.0.0 requires backpack/crud 0.* -> satisfiable by backpack/crud[0.4.1, 0.5.0, 0.5.1, 0.5.10, 0.5.9, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.6.5, 0.7, 0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.7.5, 0.7.6, 0.7.7, 0.7.8, 0.7.9, 0.8.0, 0.8.1, 0.8.10, 0.8.11, 0.8.12, 0.8.13, 0.8.14, 0.8.15, 0.8.16, 0.8.17, 0.8.18, 0.8.2, 0.8.3, 0.8.4, 0.8.5, 0.8.6, 0.8.7, 0.8.8, 0.8.9, 0.9.0, 0.9.1, 0.9.10, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6, 0.9.7, 0.9.8, 0.9.9] but these conflict with your requirements or minimum-stability.
- backpack/settings 2.0.4 requires backpack/crud 2.* -> satisfiable by backpack/crud[2.0.0, 2.0.1, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.0.15, 2.0.16, 2.0.17, 2.0.18, 2.0.19, 2.0.2, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 2.0.24, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, v2.x-dev] but these conflict with your requirements or minimum-stability.
- Installation request for backpack/settings ^2.0 -> satisfiable by backpack/settings[2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5].
Simptoms: everything looks fine in the controller, model, request, but validation errors DO NOT SHOW; After validation (which does happen), you are redirected back to the create/edit page, but without showing any errors and with emptied fields.
If you happen to spend A LOT of time trying to figure out, here it is:
routes.php
file, make sure your CRUD panel is not behind the web
middleware.That's it.
Now if we have an validator errors we just redirected back so better way its to show errors for user.
Is this considered?
Right now all rows are queried.
With thousands of rows and custom columns? this might get pretty heavy...
I've some issues with setFromDB
method, specially on edit views with relations fields.
I'm ok to try to fix them, but I want to know if the setFromDB
method will be kept in the future, or if you want to delete it, in benefit to manually addField
methods
The browse field type works fine when Laravel is installed in a root folder, but not when the site is located in a subfolder.
Example:
On http://localhost/
the URL of the browse iframe point correctly to elFinder popup layout.
On http://localhost/MySite/public/
the URL is /admin/elfinder/popup/image-filemanager
instead of /MySite/public/admin/elfinder/popup/image-filemanager
I am receiving this error and do not know how to fix it.
Invalid backend configuration.
Readable volumes not available.
Help please
Thanks
Keep this in mind: https://dotdev.co/how-to-write-a-readme-that-rocks-bc29f279611a#.8wgk7e1k7
I was thinking maybe we can do a better version of this function to add two options. This feature seems to be necesary when:
In order to minimize the number of clicks needed to insert a row.
Alongside the regular buttons, there should be a Clone button, in this order: Edit | Clone | Delete
Behaviour:
Details:
What would you think about showing a checkbox field in the list table view, as a checkbox vs 1/0? (Not sure the direction you might be going on these, so didn't want to just create a pull request.)
I'm using this, around line 90 in list.blade.php, myself:
@elseif (isset($column['type']) && $column['type']=='checkbox')
{{-- checkbox with loose false/null/0 checking --}}
<td><input type="checkbox"
@unless(strip_tags($entry->{$column['name']}) == false)
checked = "checked"
@endunless
></td>
PS. Started using backpack pretty heavily on a new project -- thanks so much for creating this, and making it so flexible!
When I try to use a select2_multiple field instead of a select_multiple field, I get this error:
ErrorException in b58d2ac85e3cfb89e50920aa215a69bd96d9acac.php line 25: Array to string conversion (View: D:\Progetti\instalmec.it\Instalmec\vendor\backpack\crud\src\resources\views\fields\select2_multiple.blade.php) (View: D:\Progetti\instalmec.it\Instalmec\vendor\backpack\crud\src\resources\views\fields\select2_multiple.blade.php) (View: D:\Progetti\instalmec.it\Instalmec\vendor\backpack\crud\src\resources\views\fields\select2_multiple.blade.php)
I changed nothing else the field type, from select_multiple
to select2_multiple
The programmer should have the ability to choose the order the fields, after the fact.
This function in Crud.php should be completed:
$this->crud->setFieldOrder(['field_1', 'field_2', 'field_3'], 'update/create/both');
hello!
How can i make image file on insert or update with rename and make thumb files?
This is my Error
How to fix this.. Please help me
No hint path defined for [backpack]. (View: C:\wamp\www\partner\resources\views\vendor\elfinder\elfinder.blade.php)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.