Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/Http/Controllers/Admin/FluentMonsterCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ protected function setupCreateOperation()
])
->fake(true)
->tab('Selects');
CRUD::field('wysiwyg')->type('summernote')->label('WYSIWYG')->tab('Editors');

CRUD::field('icondummy')
->type('relationship')
->label('Relationship to non-nullable model (belongs_to_non_nullable)')
->entity('icondummy')
->attribute('icon')
->model(\App\Models\Icon::class)
->allows_null(false)
->tab('Selects');

// -----------------
// UPLOADS tab
Expand Down
18 changes: 15 additions & 3 deletions app/Http/Controllers/Admin/HeroCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ protected function setupCreateOperation()
CRUD::field('name');
CRUD::field('stories')
->label('Stories'.backpack_new_badge())
->subfields(self::getMonsterSubfields())
->subfields([
[
'name' => 'name',
],
[
'name' => 'monsters',
'type' => 'select2_multiple',
'model' => \App\Models\Monster::class,
'entity' => 'monsters',
'attribute' => 'text',
'pivot' => true,
],
])
->hint('<small class="float-right">Select the related Story over a <code>belongsToMany</code> relationship (n-n) with extra pivot fields.</small>');
}

Expand All @@ -80,7 +92,7 @@ public static function getMonsterSubfields()
{
$subfields = CaveCrudController::getMonsterSubfields();

foreach ($subfields as $key => $subfield) {
/* foreach ($subfields as $key => $subfield) {
// fake fields don't work here for some reason
// TODO: fix the problem and remove this
if (isset($subfield['fake']) && $subfield['fake']) {
Expand All @@ -100,7 +112,7 @@ public static function getMonsterSubfields()
continue;
}
}

*/
return $subfields;
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/MonsterCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ protected function addCustomCrudFilters()
$this->crud->addFilter(
[ // add a "simple" filter called Draft
'type' => 'simple',
'name' => 'checkbox',
'name' => 'checkbox_filter',
'label' => 'Simple',
],
false, // the simple filter has no values, just the "Draft" label specified above
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public function setup()
parent::setup();

// get the owner parameter
$this->owner = \Route::current()->parameter('owner');
$this->owner = \Route::current()?->parameter('owner');

if (!$this->owner) {
abort(404);
}

// set a different route for the admin panel
CRUD::setRoute(config('backpack.base.route_prefix').'/pet-shop/owner/'.$this->owner.'/pets');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/MonsterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function rules()
return [
'text' => 'required|min:5|max:255',
'email' => 'nullable|email',
'icondummy' => 'required',
// 'icondummy' => 'required',
];
}

Expand Down
5 changes: 5 additions & 0 deletions app/Models/Cave.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function monster()
return $this->hasOne(\App\Models\Monster::class);
}

public function category()
{
return $this->monster()->getRelated()->category();
}

protected function location(): \Illuminate\Database\Eloquent\Casts\Attribute
{
return \Illuminate\Database\Eloquent\Casts\Attribute::make(
Expand Down
12 changes: 6 additions & 6 deletions app/Models/Hero.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class Hero extends Model
'id' => 'integer',
];

public function monster()
{
return $this->hasOne(\App\Models\Monster::class);
}

public function stories()
{
return $this->belongsToMany(\App\Models\Story::class, 'monsters')
->withPivot((new \App\Models\Monster())->getFillable());
->withPivot(array_filter((new \App\Models\Monster())->getFillable(), function ($item) {
// fields that are on fillable but are not part of model table
$columnsToRemove = ['fake-text', 'fake-switch', 'fake-select', 'fake-checkbox', 'editable_checkbox'];

return !in_array($item, $columnsToRemove);
}));
}
}
7 changes: 7 additions & 0 deletions app/Models/Monster.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Monster extends Model
'browse_multiple' => 'array',
'status' => MonsterStatus::class,
'features' => 'array',
'table' => 'array',
'extras' => 'array',
// optional casts for select from array fields that allow multiple selection
// 'select_from_array' => 'array',
// 'select2_from_array' => 'array'
Expand Down Expand Up @@ -342,4 +344,9 @@ public function setUploadMultipleAttribute($value)

$this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
}

public function setIcondummyAttribute($value)
{
$this->attributes['belongs_to_non_nullable'] = $value;
}
}
2 changes: 0 additions & 2 deletions app/Models/PetShop/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace App\Models\PetShop;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
use \Backpack\CRUD\app\Models\Traits\CrudTrait;
use \App\Models\Traits\LogsActivity;
use HasFactory;

protected $fillable = [
'body',
Expand Down
6 changes: 3 additions & 3 deletions app/Models/PetShop/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Passport extends Model
protected $casts = [
'id' => 'integer',
'pet_id' => 'integer',
'issuance_date' => 'date',
'expiry_date' => 'date',
'birth_date' => 'date',
'issuance_date' => 'date:Y-m-d',
'expiry_date' => 'date:Y-m-d',
'birth_date' => 'date:Y-m-d',
];

public function pet()
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Story.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

use App\Models\Traits\LogsActivity;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Story extends Model
{
use CrudTrait;
use LogsActivity;
use HasFactory;

/**
* The attributes that are mass assignable.
*
Expand Down
2 changes: 2 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class User extends Authenticatable implements MustVerifyEmail
'name', 'email', 'password',
];

public $timestamps = true;

/**
* The attributes that should be hidden for arrays.
*
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"symfony/dom-crawler": "^7",
"backpack/generators": "^4.1",
"barryvdh/laravel-debugbar": "^3.2",
"backpack/test-generators": "dev-main"
"backpack/test-generators": "^1.0"
},
"repositories": [
{
Expand All @@ -75,6 +75,11 @@
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
Expand Down
Loading