Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
init treeview dev
Browse files Browse the repository at this point in the history
  • Loading branch information
adr1enbe4udou1n committed Sep 6, 2020
1 parent 344d24a commit 1081c32
Show file tree
Hide file tree
Showing 48 changed files with 1,146 additions and 243 deletions.
2 changes: 2 additions & 0 deletions docs/guide/crud/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ See all supported field properties :
| **source** | `string` | Resource property to display. |
| **type** | `string` | Type of [field](../components/fields.md) to use. |
| **label** | `string` | Column title header, use [localized property source](../i18n.md) by default. |
| **labelKey** | `string` | Override default source as i18n key message |
| **sortable** | `boolean` | Activate server-side sort. |
| **align** | `string` | You can Use `left`, `right`, `center` for each cell `align` attribute. |
| **link** | `string` | Use any valid `show` or `edit` action if you want to wrap field inside resource action link. |
Expand Down Expand Up @@ -327,6 +328,7 @@ See all supported field properties :
| **source** | `string` | Resource property to display. |
| **type** | `string` | Type of [input](../components/inputs.md) to use. |
| **label** | `string` | Column title header, use [localized property source](../i18n.md) by default. |
| **labelKey** | `string` | Override default source as i18n key message |
| **alwaysOn** | `boolean` | Keep filter always active and visible. Not removable. |
| **attributes** | `object` | All props or attributes to merge to the [input component](../components/inputs.md). |

Expand Down
2 changes: 1 addition & 1 deletion examples/api-platform/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
transpileDependencies: ["vuetify", "vtec-admin"],
transpileDependencies: ["vuetify"],
pluginOptions: {
i18n: {
locale: "en",
Expand Down
16 changes: 11 additions & 5 deletions examples/demo-laravel/app/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
*
* @property int $id
* @property int $publisher_id
* @property int $category_id
* @property string|null $isbn
* @property string $title
* @property string $description
* @property string $summary
* @property string $category
* @property array $formats
* @property float $price
* @property bool $commentable
* @property array $tags
* @property Carbon $publication_date
* @property-read Category $category
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Review[] $reviews
* @property-read int|null $reviews_count
* @property-read \App\Publisher $publisher
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Author[] $authors
* @property-read int|null $authors_count
* @property-read mixed $translations
* @property-read \Illuminate\Database\Eloquent\Collection|Media[] $media
* @property-read int|null $media_count
* @method static \Illuminate\Database\Eloquent\Builder|\App\Book newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Book newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Book query()
Expand All @@ -40,9 +44,6 @@
* @method static \Illuminate\Database\Eloquent\Builder|\App\Book pricierThan($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Book commentables()
* @mixin \Eloquent
* @property-read mixed $translations
* @property-read \Illuminate\Database\Eloquent\Collection|Media[] $media
* @property-read int|null $media_count
*/
class Book extends Model implements HasMedia
{
Expand All @@ -58,7 +59,7 @@ class Book extends Model implements HasMedia
'description',
'summary',
'price',
'category',
'category_id',
'formats',
'commentable',
'tags',
Expand Down Expand Up @@ -86,6 +87,11 @@ public function registerMediaCollections(): void
$this->addMediaCollection('extract')->singleFile();
}

public function category()
{
return $this->belongsTo(Category::class);
}

public function publisher()
{
return $this->belongsTo(Publisher::class);
Expand Down
69 changes: 69 additions & 0 deletions examples/demo-laravel/app/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
use Spatie\Translatable\HasTranslations;

/**
* App\Category
*
* @property int $id
* @property string $name
* @property string $type
* @property int|null $parent_id
* @property int|null $order_column
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property Category $parent
* @method static \Illuminate\Database\Eloquent\Builder|Category newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Category newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Category query()
* @mixin \Eloquent
*/
class Category extends Model implements Sortable
{
use HasTranslations;
use SortableTrait;

protected $fillable = ['name'];

public $translatable = ['name'];

protected function getLocale(): string
{
return request()->header('locale') ?: app()->getLocale();
}

public function parent()
{
return $this->belongsTo(Category::class);
}

public function children()
{
return $this->hasMany(Category::class, 'parent_id');
}

public function buildSortQuery()
{
return static::query()
->where('type', $this->type)
->where('parent_id', $this->parent_id);
}

public function toArray()
{
return [
'id' => $this->id,
'name' => $this->name,
];
}

public function __toString()
{
return $this->name;
}
}
4 changes: 2 additions & 2 deletions examples/demo-laravel/app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function index()
AllowedFilter::scope('published_after'),
])
->allowedSorts(['id', 'isbn', 'title', 'price', 'publication_date'])
->allowedIncludes(['publisher', 'authors', 'reviews', 'media'])
->allowedIncludes(['category', 'publisher', 'authors', 'reviews', 'media'])
->paginate()
);
}
Expand All @@ -62,7 +62,7 @@ public function index()
*/
public function show(Book $book)
{
return new BookResource($book->load(['publisher', 'authors', 'reviews', 'media']));
return new BookResource($book->load(['category', 'publisher', 'authors', 'reviews', 'media']));
}

/**
Expand Down
91 changes: 91 additions & 0 deletions examples/demo-laravel/app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreCategory;
use App\Http\Requests\UpdateCategory;
use App\Http\Resources\Category as CategoryResource;
use App\Category;
use Illuminate\Http\Request;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;

class CategoryController extends Controller
{
public function __construct()
{
$this->authorizeResource(Category::class);
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/
public function index()
{
return CategoryResource::collection(
QueryBuilder::for(Category::class)
->allowedFields(['id', 'name'])
->allowedFilters([
AllowedFilter::exact('id'),
AllowedFilter::exact('type'),
'name',
])
->ordered()
->get()
);
}

/**
* Display the specified resource.
*
* @param \App\Category $category
* @return CategoryResource
*/
public function show(Category $category)
{
return new CategoryResource($category);
}

/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return CategoryResource
*/
public function store(StoreCategory $request)
{
$category = Category::create($request->all());

return new CategoryResource($category);
}

/**
* Update the specified resource in storage.
*
* @param UpdateCategory $request
* @param \App\Category $category
* @return CategoryResource
*/
public function update(UpdateCategory $request, Category $category)
{
$category->update($request->all());

return new CategoryResource($category);
}

/**
* Remove the specified resource from storage.
*
* @param \App\Category $category
* @return \Illuminate\Http\Response
* @throws \Exception
*/
public function destroy(Category $category)
{
$category->delete();

return response()->noContent();
}
}
1 change: 0 additions & 1 deletion examples/demo-laravel/app/Http/Requests/StoreBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function rules()
'publisher_id' => 'required',
'isbn' => 'required|isbn',
'title' => 'required',
'category' => 'required|in:novel,comic,cook,economy,politics,history,fantasy,biography',
'description' => 'required',
'formats.*' => 'in:pocket,paperback,pdf,epub,kindle',
'price' => 'required|numeric',
Expand Down
31 changes: 31 additions & 0 deletions examples/demo-laravel/app/Http/Requests/StoreCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreCategory extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'type' => 'required|in:book',
];
}
}
1 change: 0 additions & 1 deletion examples/demo-laravel/app/Http/Requests/UpdateBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function rules()
'publisher_id' => 'sometimes|required',
'isbn' => 'sometimes|required|isbn',
'title' => 'sometimes|required',
'category' => 'sometimes|required|in:novel,comic,cook,economy,politics,history,fantasy,biography',
'description' => 'sometimes|required',
'formats.*' => 'sometimes|in:pocket,paperback,pdf,epub,kindle',
'price' => 'sometimes|required|numeric',
Expand Down
31 changes: 31 additions & 0 deletions examples/demo-laravel/app/Http/Requests/UpdateCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateCategory extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'sometimes|required',
'type' => 'sometimes|required|in:book',
];
}
}
1 change: 1 addition & 0 deletions examples/demo-laravel/app/Http/Resources/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function toArray($request)
{
$attributes = parent::toArray($request);

$attributes['category'] = Category::make($this->whenLoaded('category'));
$attributes['publisher'] = Publisher::make($this->whenLoaded('publisher'));
$attributes['authors'] = Author::collection($this->whenLoaded('authors'));
$attributes['reviews'] = Review::collection($this->whenLoaded('reviews'));
Expand Down
19 changes: 19 additions & 0 deletions examples/demo-laravel/app/Http/Resources/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Resources;

use Vtec\Crud\Http\Resources\BaseResource;

class Category extends BaseResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}
Loading

0 comments on commit 1081c32

Please sign in to comment.