$this->crud->addField([
'name' => 'title',
'label' => "My Title",
'type' => 'text',
'box' => 'Box name here'
]);
$this->crud->setBoxOptions('Details', [
'side' => true, // Place this box on the right side?
'class' => "box-info", // CSS class to add to the div. Eg, <div class="box box-info">
'collapsed' => true, // Collapse this box by default?
]);
// Article Model
class Article extends \Backpack\NewsCRUD\app\Models\Article
{
use Sluggable, SluggableScopeHelpers;
use HasTranslations;
use UploadableFile;
protected $fillable = ['slug', 'title', 'content', 'image', 'status', 'category_id', 'featured', 'date', 'document', 'document_2'];
protected $translatable = ['slug', 'title', 'content'];
public function uploadableFiles(): array
{
return [
['name' => 'document'],
['name' => 'document_2', 'slug' => 'title']
];
}
}
// ArticleCrudController
$this->crud->addField([
'label' => 'Image',
'name' => 'image',
'type' => 'image',
'upload' => true,
'crop' => true, // set to true to allow cropping, false to disable
'aspect_ratio' => 0, // ommit or set to 0 to allow any aspect ratio
'prefix' => '/storage/',
]);
$this->crud->addField([
'label' => 'Document',
'name' => 'document',
'type' => 'upload',
'upload' => true,
'prefix' => '/storage/',
]);
$this->crud->addField([
'label' => 'Document 2',
'name' => 'document_2',
'type' => 'upload',
'upload' => true,
'prefix' => '/storage/',
]);
public function rules()
{
return [
'name' => ' parameters must be valid mime types
];
}
public function messages()
{
return [
'file_upload_crud' => 'The :attribute must be a valid file.',
];
}
namespace App\Models;
use Backpack\CRUD\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Novius\Backpack\CRUD\ModelTraits\UploadableImage;
class Example extends Model
{
use CrudTrait;
use UploadableImage;
protected $fillable = ['title', 'image', 'thumbnail'];
public function uploadableImages()
{
return [
[
'name' => 'image', // The attribute name where to store the image path
'slug' => 'title', // The attribute name from which to generate the image file name (optionnal)
],
[
'name' => 'thumbnail',
],
];
}
}
namespace App\Models;
use Backpack\CRUD\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Novius\Backpack\CRUD\ModelTraits\UploadableImage;
class Example extends Model
{
use CrudTrait;
use UploadableImage {
imagePathSaved as imagePathSavedNative;
imagePathDeleted as imagePathDeletedNative;
}
protected $fillable = ['title', 'image', 'thumbnail'];
public function uploadableImages()
{
return [
[
'name' => 'image', // The attribute name where to store the image path
'slug' => 'title', // The attribute name from which to generate the image file name (optionnal)
],
[
'name' => 'thumbnail',
],
];
}
/**
* Callback triggered after image saved on disk
*/
public function imagePathSaved(string $imagePath, string $imageAttributeName = null, string $diskName = null)
{
if (!$this->imagePathSavedNative()) {
return false;
}
// Do what you want here
return true;
}
/**
* Callback triggered after image deleted on disk
*/
public function imagePathDeleted(string $imagePath, string $imageAttributeName = null, string $diskName = null)
{
if (!$this->imagePathDeletedNative()) {
return false;
}
// Do what you want here
return true;
}
}
// Set a custom index route
$this->crud->setIndexRoute('crud.slide.index', ['slideshow' => (int) request('slideshow')]);
// Set a custom reorder route
$this->crud->setReorderRoute('crud.slide.reorder', ['slideshow' => (int) request('slideshow')]);
sh
php artisan vendor:publish --provider="Novius\Backpack\CRUD\CrudServiceProvider" --force
sh
php artisan vendor:publish --provider="Novius\Backpack\CRUD\CrudServiceProvider" --tag="config"
sh
php artisan permissions:generate // Insert permissions in database for each CRUD controllers.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.