1. Go to this page and download the library: Download aldeebhasan/naive-crud library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aldeebhasan / naive-crud example snippets
use Aldeebhasan\NaiveCrud\Http\Controllers\BaseController;
class BlogController extends BaseController
{
//ng $policy = BlogPolicy::class;
//optional: define the blog request class
//The package is smart enough to it will look for this class under app/http/Requests folder
protected ?string $modelRequestForm = BlogRequest::class
//optional: define the blog resource class
//The package is smart enough to it will look for this class under app/http/Resources folder
protected ?string $modelResource = BlogResource::class
}
//applied over all the routes
public function baseQuery(Builder $query): Builder
{
return $query;
}
//applied over the index routes + along with base query
protected function indexQuery(Builder $query): Builder
{
return $query;
}
//applied over the show routes + along with base query
protected function showQuery(Builder $query): Builder
{
return $query;
}
//applied over the search routes + along with base query
protected function searchQuery(Builder $query): Builder
{
return $query;
}
//applied over the export routes + along with base query
protected function exportQuery(Builder $query): Builder
{
return $query;
}
use Aldeebhasan\NaiveCrud\Http\Controllers\BaseController;
class BlogController extends BaseController
{
//he blog policy class
protected string $policy = BlogPolicy::class;
}
//policy class
class BlogPolicy extends BasePolicy
{
}
$user->can('index_blogs',Blog::class) // => true
use Aldeebhasan\NaiveCrud\Http\Controllers\BaseController;
class BlogController extends BaseController
{
// protected ?string $modelResource = BlogResource::class
}
//resource class
class BlogResource extends BaseResource
{
// response for index route
public function toIndexArray(Request $request): array
{
return [
'id' => $this->id,
'slug' => str($this->title)->slug(),
'title' => $this->title,
];
}
// response for show route
public function toShowArray(Request $request): array
{
return [
'id' => $this->id,
'slug' => str($this->title)->slug(),
'title' => $this->title,
'description' => $this->description,
];
}
// response for search route
public function toSearchArray(Request $request): array
{
return [
'key' => $this->id,
'value' => $this->title,
];
}
}
use Aldeebhasan\NaiveCrud\Http\Controllers\BaseController;
class BlogController extends BaseController
{
// protected ?string $modelRequestForm = BlogRequest::class
}
//Request class
class BlogRequest extends BaseRequest
{
public function storeRules(): array
{
return [
'title' => ' }
public function toggleRules(): array
{
return [
'active' => 'nullable|boolean',
];
}
}
use Aldeebhasan\NaiveCrud\Http\Controllers\BaseController;
class BlogController extends BaseController
{
// ];
}
//Request class
class CommonFilter implements FilterUI
{
public function fields(): array
{
return [
new FilterField(field: 'search', callback: fn ($q, $val) => $q->search($val)),
new FilterField(field: 'category_id'),
];
}
}
use Aldeebhasan\NaiveCrud\Http\Controllers\BaseController;
class BlogController extends BaseController
{
// ];
}
//Request class
class CommonSorter implements SortUI
{
public function fields(): array
{
return [
new SortField(
field: 'category_id',
callback: fn ($q, $direction) {
$q->orderBy(
Category::whereColumn('categories.id','blogs.category_id')->select('categories.priority')),
$direction
);
},
new SortField(field: 'id'),
];
}
}
...
completedJobNotification = ExportDoneNotification::class
...
class ExportDoneNotification extends Notification{
public function __construct(protected string $path) {}
}
php artisan vendor:publish --tag=naive-crud
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.