Package Data | |
---|---|
Maintainer Username: | d4nd3v |
Package Create Date: | 2017-01-21 |
Package Last Update: | 2017-12-04 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-05 15:04:08 |
Package Statistics | |
---|---|
Total Downloads: | 146 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 0 |
Total Forks: | 0 |
Total Open Issues: | 0 |
composer require d4nd3v/crud:dev-master
Add the provider in app/Providers/AppServiceProvider.php
public function register()
{
...
if ($this->app->environment() !== 'production') {
$this->app->register('D4nd3v\Crud\CrudServiceProvider');
}
}
Run php artisan generate:crud TABLE_NAME
from the console.
|Options |Description | |:---------------------------------|:---------------------------| |--overwrite=false | overwrite existing files | |--crud=CRUD | C(reate) R(read) U(pdate) D(elete) | |--model_only=false | only generates model file | |--parent_of=TABLE1,TABLE2,TABLE3 | add links & "belongs to" in model | |--child_of=TABLE4,TABLE5,TABLE6 | generates links to parent | |--many_with=TABLE1,TABLE2 | many to many relation | |--upload=field1,field2 | transformed to file upload fields |
--crud=RD
=> all actions without C-reate and U-pdate--many_with
adds:...$this->belongsToMany...
...->sync(request()->input(....
...list from MNY_TBL...
...js select2 MNY_TBL...
If you need pagination don't forget to run:
php artisan vendor:publish --tag=laravel-pagination
The generated files are:
####For User Roles (or any other filter)####
in ```UsersController.php````
$orderBy = $request->input('by', 'id');
....
$roles = array();
if (class_exists(Role::class)) {
$roles = Role::get();
}
if(!empty(request()->input('role'))) {
$items = User::role(request()->input('role'))->orderBy($orderBy, $order)->paginate(20);
} else {
$items = User::orderBy($orderBy, $order)->paginate(20);
}
return view('users.index')
->withItems($items)
->withPage($request->input('page', 1))
->withOrder($order)
->withOrderBy($orderBy)
->withRoles($roles);
in index.blade.php
@section('content')
.....
@if($roles)
<a href="?role=">all</a>
@foreach($roles as $role)
<a href="?role={{ $role->name }}"
@if(request()->input('role')==$role->name) class="active" @endif
>{{ $role->name }}</a>
@endforeach
<hr>
@endif