Skip to content

Digging Deeper

Introduction

This section describes how you make your application easily.

Artisan Command

Artisan is the command-line interface included with Laraframe. It provides a number of helpful commands that can assist you while you build your application. To view a list of all available Artisan commands, you may run php artisan list command.

Additional Artisan Command

Clear Command: Execute php artisan clear:all artisan command will clear config, cache, route and view cache. You can also clear config and cache only by running php artisan clear:all --only=config,cache or php artisan clear:all --except=route,view

Make Interface Command: Execute php artisan make:interface artisan command will create a new Interface inside your Repository directory.

Make Repository Command: Execute php artisan make:repository artisan command will create a new Repository Class inside your Repository directory. You can also create you Interface and Model by passing -i and -m option along with this command. For example php artisan make:repository PostRepositiry -i PostInterface -m Models/Post. If the Interface and model are created before then the Interface and Model will use inside your Repository Class automatically. Otherwise you have to implements its manually. Make sure bind you Repository with related Interface in RepositoryServiceProvider.

Make Service Command: Execute php artisan make:service artisan command will create a new Service inside your Services directory.

Make View Command: Execute php artisan make:view artisan command will create a new view inside your resources/views directory.

Fake Field

Fake field will hide original form field name from client. Every time when you reload your form it will change the form field name.

To use fake field you need make sure some configuration. First you need to add fields name inside your model $fakeFields protected property like

protected $fakeFields = ['username', 'password', 'email'];

Second insider for form you need to add @basekey or <input type="hidden" value="{{base_key()}}" name="base_key">

Third use fake_field() helper function inside your form filed name to generate fake field for you.

<input name="{{ fake_field('name')}}" value=""> 

N:B: If you don't add field name to $fakeFields then the fake_field() will return plain field name.

Confing

Config is the central point of your application configurations. Here you can change any of your application configurations from config directory. We added some additional configuration file for easier development.

adminsetting.php holds all of your admin settings fields and their attributes.

commonconfig.php holds all of your application specific configurations.

fakefields.php holds fake related configurations that describes in Fake Field section.

navigation.php holds menu registered places and menu template configurations.

routeapipermission.php holds all of your API routes for Role Management

routepermission.php holds all of your routes for Role Management

Helpers

In Helpers files there are set of constant and function that you can use anywhere in the project even in the view. All helpers files are located in app\Helpers directory. If you want to create another helper function then create a php file inside app\Helpers directory and add the file path into composer.json file > files section bellow our helper files.

"autoload": {
        "files": [
            "app/Helpers/helpers.php",
            "app/Helpers/corearrays.php",
            "app/Helpers/coreconstants.php"
            "app/Helpers/new.php"
        ]
    }

corearrays.php holds all of your list options. For example active status. You call the function with a key for the key value.

function active_status($input = null) {
        $output = [
            ACTIVE_STATUS_ACTIVE => __('Active'),
            ACTIVE_STATUS_INACTIVE => __('Inactive'),
        ];

        return is_null($input) ? $output : $output[$input];
    }

coreconstants.php holds all of your application specific constants.

helpers.php holds all of your application specific functions.

List of helper functions.

company_name(): return: company name.

company_logo(): return: company logo.

random_string(): parameters: length, characters (optional) return: string

admin_settings(): parameters: key, fromDatabase:boolean (optional) return: value

check_language(): parameters: language return: language (if not exists return null)

set_language(): parameters: language, default language (optional) return: nothing

language(): return: list of languages.

fake_field(): parameters: field_name return: fake_field_name or plain field_name if the field is not found in fake_field lists.

base_key(): return: encrypted key

encode_decode(): parameters: string, decode:boolean (optional) return: encoded string or decoded string if decode true

validate_date(): parameters: date, separator(optional) return: boolean

has_permission(): parameters: route_name, user_id(optional), is_link(optional), is_api(optional) return: boolean

is_json(): parameters: string return: boolean

is_current_route(): parameters: route_name, active_class_name(optional), must_have_route_parameters(optional), optional_route_parameters(optional) return: active_class_name or empty string if not found.

available_in_parameters(): parameters: route_parameter, optional_parameters(optional) return: boolean

return_get(): parameters: key, value(optional) return: ' selected' or empty string if not found.

array_to_string(): parameters: array,separator(optional), key:boolean(optional), is_seperator_at_ends:boolean(optional) return: string

valid_image(): parameters: path, image_name return: boolean

get_avatar(): parameters: avatar_name return: absolute path of the avatar

get_user_specific_notice(): parameters: user_id(optional) return: last 5 notice and unread notice count

get_nav(): parameters: place, template(optional) return: html content of the menu

get_breadcrumbs(): return: array of urls

get_system_notices(): return: list of system notices

get_available_timezones(): return: list of timezone

form_validation(): parameters: errors, field_name return: bootstrap class

get_user_roles(): return: list of user roles

get_image(): parameters: image_name return: absolute path of the image

Data List

By using DataListService you can build a list page just in a minutes. Pass your paginated data into dataList function as bellow:

    $userModel = app(UserInterface::class);
    $searchFields = [
            ['username', __('Username')],
            ['email', __('Email')],
            ['first_name', __('First Name')],
            ['last_name', __('Last Name')],
        ];
        $orderFields = [
            ['first_name', __('First Name')],
            ['users.id', __('Serial')],
            ['last_name', __('Last Name')],
            ['email', __('Email')],
            ['username', __('Username')],
            ['users.created_at', __('Registered Date')],
        ];
        $joinArray = [
            ['user_role_managements', 'user_role_managements.id', '=', 'users.user_role_management_id'],
            ['user_infos', 'user_infos.user_id', '=', 'users.id'],
        ];
        $select = [
            'users.*', 'role_name', 'first_name', 'last_name'
        ];

        $paginatedData = $userModel->paginateWithFilters($searchFields, $orderFields, null, $select, $joinArray);
        $data = app(DataListService::class)->dataList($paginatedData, $searchFields, $orderFields);

It will return 3 items $data['items], $data[filters] && $data['pagination']. And view will look like bellow:

@extends('layouts.master')
@section('title', $title)
@section('content')
    <div class="row">
        <div class="col-lg-12">
            @component('components.card', ['type' => 'info'])
                @slot('header')
                    {!!  $list['filters'] !!}
                @endslot
                @component('components.table',['class'=> 'cm-data-table'])
                    @slot('thead')
                        <tr class="bg-info">
                            <th class="all">{{ __('Email') }}</th>
                            <th class="min-phone-l">{{ __('First Name') }}</th>
                            <th class="min-phone-l">{{ __('Last Name') }}</th>
                            <th class="min-phone-l">{{ __('User Group') }}</th>
                            <th class="min-phone-l">{{ __('Username') }}</th>
                            <th class="none">{{ __('Registered Date') }}</th>
                            <th class="text-center min-phone-l">{{ __('Status') }}</th>
                            <th class="text-center all no-sort">{{ __('Action') }}</th>
                        </tr>
                    @endslot

                    @foreach($list['items'] as $key=>$user)
                        <tr>
                            <td>
                                @if(has_permission('users.show'))
                                    <a href="{{ route('users.show', $user->id) }}">{{ $user->email }}</a>
                                @else
                                    {{ $user->email }}
                                @endif
                            </td>
                            <td>{{ $user->first_name }}</td>
                            <td>{{ $user->last_name }}</td>
                            <td>{{ $user->role_name}}</td>
                            <td>{{ $user->username }}</td>
                            <td>{{ $user->created_at->format('Y-m-d') }}</td>
                            <td class="text-center">{!! $user->is_active ? '<i class="fa fa-check text-success"></i>' : '<i class="fa fa-times text-danger"></i>' !!}</td>
                            <td class="cm-action">
                                <div class="btn-group pull-right">
                                    <button type="button" class="btn btn-sm btn-info dropdown-toggle"
                                            data-toggle="dropdown"
                                            aria-expanded="false">
                                        <i class="fa fa-gear"></i>
                                    </button>
                                    <div class="dropdown-menu" role="menu">
                                        <a class="dropdown-item" href="{{ route('users.show',$user->id)}}"><i
                                                class="fa fa-eye"></i> {{ __('Show') }}</a>
                                        <a class="dropdown-item" href="{{ route('users.edit',$user->id)}}"><i
                                                class="fa fa-pencil-square-o fa-lg text-info"></i> {{ __('Edit Info') }}
                                        </a>
                                        <a class="dropdown-item" href="{{ route('users.edit.status',$user->id)}}"><i
                                                class="fa fa-pencil-square fa-lg text-info"></i> {{ __('Edit Status') }}
                                        </a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                @endcomponent
                @slot('footer')
                    {!! $list['pagination'] !!}
                @endslot
            @endcomponent
        </div>
    </div>

@endsection

@section('style')
    <link rel="stylesheet" href="{{ asset('vendor/bootstrap4-datetimepicker/css/bootstrap-datetimepicker.min.css') }}">
    <link rel="stylesheet" href="{{ asset('vendor/datatables/dataTables.bootstrap4.min.css') }}">
@endsection

@section('script')
    <!-- for datatable and date picker -->
    <script src="{{ asset('vendor/bootstrap4-datetimepicker/js/bootstrap-datetimepicker.min.js') }}"></script>
    <script src="{{asset('vendor/datatables/datatables.min.js')}}"></script>
    <script src="{{asset('vendor/datatables/dataTables.bootstrap4.min.js')}}"></script>
    <script src="{{asset('vendor/datatables/table-datatables-responsive.js')}}"></script>
    <script type="text/javascript">
        //Init jquery Date Picker
        $('.datepicker').datetimepicker({
            format: 'YYYY-MM-DD',
        });
    </script>
@endsection