Advanced laravel system to build admin panel
PHP >= 5.6.4 , PHP Curl extension
download all files
now type this line on your console
composer install
php artisan key:generate
composer create-project --prefer-dist laraflat/laraflat
php artisan migrate
php artisan db:seed
php artisan serve
email : admin@gmail.com
pass : admin
http://127.0.0.1:8000/admin/home
php artisan make:admin_model NameOfModel
create langauge files
Add Item to AdminAPanel Menu
Create model with update , add validation
create Datatable class and html
Create Controller with add,edit,delete,store,update actions
Create View for add , edit, show
Generate Admin route
Create Api class with view,view by id ,delete,store,update
Generate Api route
Create transform file for each api calss
Create Migration file
Acl permission system
setting system
multi theme for admin panel
support multi language
Ů‹ we generate two request file one for store data other for update data
We Generate two Requests file one for update and other for add
app\Application\Requests\Admin\ModelRequestName\AddRequestModelname
app\Application\Requests\Admin\ModelRequestName\UpdateRequestModelname
the first one will use in store function on the controller
the secound one will use in the update function in the controller
app/Application/Model/Nameofmodel.php
this will be the model of the module it will contain the following
public $table = "Nameofmodel";
protected $fillable = [
'name'
];
app/Application/Datatables/NameofmodelDatatable.php
this is class to handel datatable .... every table in laraflat have his own class on this path so you must
configure this class to show your data
this method will handel the add,view,update action
```php
public function ajax()
{
return $this->datatables
->eloquent($this->query())
->addColumn('edit', 'admin.nameofmodel.buttons.edit')
->addColumn('delete', 'admin.nameofmodel.buttons.delete')
->addColumn('view', 'admin.nameofmodel.buttons.view')
->addColumn('name', 'admin.nameofmodel.buttons.langcol')
->make(true);
}
```
you can add or delete or customize any of this feilds
```php
protected function getColumns()
{
return [
[
'name' => "id",
'data' => 'id',
'title' => adminTrans('curd' , 'id'),
],
[
'name' => "name",
'data' => 'name',
],
[
'name' => "view",
'data' => 'view',
'title' => adminTrans('curd' , 'view'),
'exportable' => false,
'printable' => false,
'searchable' => false,
'orderable' => false,
],
[
'name' => 'edit',
'data' => 'edit',
'title' => adminTrans('curd' , 'edit'),
'exportable' => false,
'printable' => false,
'searchable' => false,
'orderable' => false,
],
[
'name' => 'delete',
'data' => 'delete',
'title' => adminTrans('curd' , 'delete'),
'exportable' => false,
'printable' => false,
'searchable' => false,
'orderable' => false,
],
];
}
```
you can see more about this from datatable documentation
app/Application/Controllers/NameofmodelControllers.php
all controller extends this class AbstractController this where the magic happen
this class have all logic to get store update add methods on Laraflat
public function __construct(Nameofmodel $model)
{
parent::__construct($model);
}
here we add the model that we add , edit , update , store , delete Don not worry laralflat write this to you
to make ot easy to make this action
here we build the datatable and render it do not worry about this all this work don by laraflat
public function index(NameofmodelDataTable $dataTable){
return $dataTable->render('admin.nameofmodel.index');
}
this function call when you show add , edit
public function show($id = null){
return $this->createOrEdit('admin.nameofmodel.edit' , $id);
}
you can pass any data to view as array as third arg in createOrEdit
this method will call on store , update action
public function store($id = null , \Illuminate\Http\Request $request){
return $this->storeOrUpdate($request , $id , 'admin/nameofmodel');
}
you can here customize your request and can check if request store by if($id == null)
this method control the view action in datatable
public function getById($id){
$fields = $this->model->getConnection()->getSchemaBuilder()->getColumnListing($this->model->getTable());
return $this->createOrEdit('admin.nameofmodel.show' , $id , ['fields' => $fields]);
}
this Method get all table column and send it with the item to the view to show details
this methods call when you try to delete the item
public function destroy($id){
return $this->deleteItem($id , 'admin/categorie')->with('sucess' , 'Done Delete categorie From system');
}
app/Application/views/admin/nameofmodel
we generate by default 7 view 3 the index , edit , show this is the common fiels
the other 4 controll the btns in datatable
app/Application/routes/admin/admin.php
laraflat append all routes for you when you excute the command php artisan make:admin_model
laraflat append all reoutes that make this actions add , edit , delete , store , update , view
int this Path app/Application/routes/admin/admin.php
this path the admin group only will have access on it
Insert item in admin menu
laraflat insert item for you when you excute the command php artisan make:admin_model
so it will appear in admin menu
database/migrations/Nameofmodel
laraflat cearet migration file for you when excute the command php artisan make:admin_model
recources/lang/ar/nameofmodel
laraflat cearet language files for you when excute the command php artisan make:admin_model
it will check available language in config\laravellocalization.php
and will generate language files for you
how to use tinymce on any texteara
just put this id on any texteara tinymce
then at the end of the page put this code
@section('script')
@include('admin.layout.helpers.tynic')
@endsection
add filed accept mluti language
laraflat loko to this file config\laravellocalization.php
to check the available language to use then you can un commnet any language form this file
now use this function to create your fileds laraflat will generate fields for each language
{!! extractFiled('name' , isset($item->name) ? $item->name : null , 'text' , 'categorie') !!}
- name => feild name
- isset($item->name) ? $item->name : null => check if this is store action or edit action
- text => type of feild
- categorie => translate file must have key name of feild
get value deppend on user language
you can use this two function getDefaultValueKey($filed)
this function will decet the user lang and show him value depend on this lang or use this
getLangValue($filed , 'ar')
this function you must pass the language you want to show
if you want to save arrays in database just make the filed name as array like the example
<input type="text" name="title[]" />
laralflat will decet the array filed and contvert it as json
laralflat fo this file app\Application\Helpers\uploadFiles.php
check this getFileFieldsName()
if the file name in this array laralflat will upload this image
<input type="file" name="image" />
if you want to upload multi image just add array to name and laraflat will take care about this
<input type="file" name="image[]" />
adminTrans('filename' , 'word')
concatenateLangToUrl('admin/cat/item/1')
get all available language
getAvLang()
some times you will have array with multi language value so you want to get just the current language
in this case use this function transformSelect()
it will return with array this value will be from the current user language
laraflat have setting table so if you want to get setting just call this function getSetting('siteTitle')
laraflat support menu system so if you want to show your menu use this function
menu('menuName')
this will build ul with li with menu itmes
We Generate apicontroller for each module you add
app\Application\Api\ModelNameApi.php
and we also generate the api routes for you
you can check this link to show how it work with angular 4 Api with angular