All You Need To Know About Blade Templates In Laravel

Blade Templates In Laravel
Let’s start with the introduction of Blade and how Laravel supports it strongly. Laravel provides a simple and powerful templating engine like as blade. You can also use PHP code in blade template views.
In fact, all blade views are compiled into plain PHP code. Blade view files use the “.blade.php “  extension and it stored in “ resources/views “
directory.

Template Inheritance:

When defining a view you use the Blade @extends directive to extend the blade layout and blade all section using
@section directives.
@extends('layouts.app')
 
@section('title', 'Page sidebar')
 
@section('sidebarDemo')
@parent
 
<p>This is sidebar demo.</p>
@endsection
 
@section('content')
<p>This is body content.</p>
@endsection
Here, we are extending layouts.app blade view so we use all section @section directives @parent directive is an append
directive to the layout’s sidebar.
Blade view may be returned from routes.
Route::get(blade/name, function () {
    return view('blade.name');
});
Displaying Data:-
You may Display data in blade bypass the variable in curly braces like:
 Route::get('bladeDemo', function () {
        return view('welcome', ['name' => 'Addweb']);
});
Here, we add the ‘Data’ in name variable so, we display the name like,
 Hello {{ $name }}.
It has not limited to displaying content, in fact, you can also put any PHP code and result of any PHP functions inside of blade echo statement.
{{ isset($name) ? $name : Test }}
Here, we use the ternary operator to check the name is exist or not. if a name exists and set so it displays name and not set name so it can display Default.

Control Structures:-

The blade provides the displaying data but in additionally blade also provides the convenient shortcut of PHP control

structure such as conditional statement and loops.
If statement:-
You may use the @if, @elseif, @else, @endif directives for the if construct.These directives function identically to their PHP counterparts.
@if (count($records) === 1)
    I have one record!
@elseif (count($records) > 1)
    I have multiple records!
@else
    I don't have any records!
@endif    
Loops:-

Blade provides simple directive parts for a looping and it is identical to their PHP counterparts

@for ($i = 0; $i < 10; $i++)
        The current value is {{ $i }}
@endfor
 
@foreach ($demos as $demo)
    <p>This is demo{{ $demo->id }}</p>
@endforeach
 
@forelse ($demos as $demo)
    <li>{{ $demo->name }}</li>
@empty
    <p>No users</p>
@endforelse
 
@while (true)
    <p>I'm looping forever.</p>
@endwhile
The Loop variables:-

When a loop is working a $loop is available inside of a loop. This variable provides some variable to use bits of information such as the current loop of an index and first or last iteration of a loop.

Hope this helped you to get most out of the system. Feel free to share your reviews or need assistance for Hire Laravel Developer then get in touch with us. Pick the best answer for your requirements.
Advertisements

USEFUL TIPS FROM EXPERTS FOR CSS PSEUDO SELECTORS

CSS Pseudo Selectors

Pseudo-class selectors are CSS selectors used to define a special state of an element or display elements in a different way. It allows us to apply a special style to any element in context of the actions being performed on it. All the different selectors that are used commonly are described in the following sections.

Content selectors
::after
::before

  • Displays content text or img after and before the defined element/tag (Note: It is not working for input tags).
  • It contains ‘Content’ property to display any text or image.

:empty

  • It counts any element as empty if it does not have any text or child tags.

:not()

  • It is negation class selector. We can ignore some tags by using :not selector.
  • For example:  :not(.class-name) { /* code */ }

=> Child selectors
:first-child

  • It will target the tag only if it is the first child of its parent.

:first-of-type

  • It will target the first element of its parent, of particular type.

:last-child

  • It will target the tag only if it is the last child of its parent.

:last-of-type

  • It will target the last element of its parent, of particular type.

:nth-child()
:nth-last-child()
:nth-last-of-type()
:nth-of-type()
:only-child
:only-of-type

  • These elements are used to find the specific child of its parent.
  • For example:

<ul>       <li>First list item</li>       <li>Second list item</li>       <li>Third list item</li>       <li>Fourth list item</li> <li> last list item</li>     </ul>     li:first-child {       color: deepPink;     }     li:nth-child(3) {       background-color: red;     }     li:last-child {       text-decoration: underline;     }

::placeholder

  • It represents the text in input/textarea fields and provides a hint to the user about the data to be filled in the form element.
  •  For example:

::placeholder {       color: #0c496d;       font-size: 14px;     }    ::-moz-placeholder {       color: #0c496d;       font-size: 14px;    }

:disabled
:enabled

  • It accepts or rejects a user interaction on a form control.
  • It is used for button, select, input, textarea…
  • For example:

HTML

<input type=”checkbox” id=”checkbox-1″ disabled><label for=”checkbox-1″>First Choice (disabled)</label> <br>         <input type=”checkbox” id=”checkbox-2″><label for=”checkbox-2″>Second Choice</label>

CSS

input[type=”checkbox”]:disabled + label{               text-decoration: line-through;                cursor: not-allowed;     color: grey;         }

:checked

  • It is used to select and style checkbox and radio-button that are checked.
  • For example:

<input type=”checkbox” name=”checks” id=”box-1″ checked> <label for=”box-1″>Initially checked.</label> <br/> <input type=”checkbox” name=”checks” id=”box-2″><label for=”box-2″>Not Checked</label>

:read-only

  • It selects any input type and textarea that is not editable.

:read-write

  • It selects any input type and textarea that is editable.

:required

  • Required is used to select form elements that have the required attribute set.

:optional

  • Optional is used to select form elements that are optional.

=> Event selectors

  • It specifies an element based on a specific state and is used to apply styles to an element when it matches that specified state.
  • These pseudo elements are used to style link elements and define different behaviors like: active, hover,  focus, visited.

:active 

  • This pseudo-class is a dynamic class which applies when an element is being activated by the user. It is used to style an element when it’s active.
  • For example:

p:active { background-color: #AAA; }

:blank

  • It is a CSS pseudo-class selector used to select pages of a printed document, such as a book, that are empty as a result of a forced page break.

:focus

  • It is used for elements that accept keyboard events or other user inputs or receive focus.
  • For example:

a:focus {     outline: 0;     background-color: black; }

Read more: https://goo.gl/5Kgm1b

Hope this helped you to get most out of the system. Feel free to share your reviews or need assistance for Web Design Services then get in touch with us. 🙂

Create Custom Multistep Form Using Ajax

Multistep Form Using Ajax
Don’t want long forms on your website? Convert it into multi-step form, as it is more convenient and provides step by

step procedure to follow by user. This blog will provide a way to create of multi step form using ajax.

https://goo.gl/P1BrVx 1. Create a menu item using hook_menu()

/** * Implementation of hook_menu(). */ function custom_menu() { $menu[‘multistep_form’] = array ( ‘title’ => ‘Multistep Form’, ‘description’ => ‘To create multistep form’, ‘page callback’ => ‘drupal_get_form’, ‘page arguments’ => array(‘ajax_multistep_form’), ‘access callback’ => TRUE, ); return $menu; }

  1. Define a callback functionIt includes stepwise fields. It contains fieldset for each step with their respective fields. Then It will includes buttons for each step.

We have called ajax_multistep_form_ajax_callback function it returns the entire form each time the function is called. Added a wrapper div “ajax_multistep_form’” to update the form using AJAX.

$form[‘buttons’][‘next’] = array ( ‘#type’ => ‘submit’, ‘#value’ => t(‘Next’), ‘#ajax’ => array ( ‘wrapper’ => ‘ajax_multistep_form’, ‘callback’ => ‘ajax_multistep_form_ajax_callback’, ), );

 

 

function ajax_multistep_form($form, &$form_state) {   // If $form_state[‘step’] is not set then set default to 1 $form_state[‘step’] = isset($form_state[‘step’]) ? $form_state[‘step’] : 1; // Add a wrapper div to update the form using AJAX $form[‘#prefix’] = ‘

‘; $form[‘#suffix’] = ‘

‘;   switch($form_state[‘step’]) { // Step 1 case 1: $fname_default_value = $lname_default_value = ”; if(isset($form_state[‘values’][‘step_1’])) { $fname_default_value = $form_state[‘values’][‘step_1’][‘fname’]; $lname_default_value = $form_state[‘values’][‘step_1’][‘lname’]; } elseif(isset($form_state[‘storage’][‘step_1’])) { $fname_default_value = $form_state[‘storage’][‘step_1’][‘fname’]; $lname_default_value = $form_state[‘storage’][‘step_1’][‘lname’]; }   $form[‘step_1’] = array( ‘#type’ => ‘fieldset’, ‘#title’ => t(”), ‘#collapsible’ => false, ‘#collapsed’ => false, ); $form[‘step_1’][‘fname’] = array( ‘#type’=>’textfield’, ‘#required’ => true, ‘#title’=>t(‘First Name’), ‘#default_value’ => $fname_default_value, ); $form[‘step_1’][‘lname’] = array( ‘#type’=>’textfield’, ‘#required’ => true, ‘#title’=>t(‘Last name’), ‘#default_value’ => $lname_default_value, ); break; // Step 2 case 2: $phone_default_value = ”; if(isset($form_state[‘values’][‘step_2’])) { $phone_default_value = $form_state[‘values’][‘step_2’][‘phone’]; } elseif(isset($form_state[‘storage’][‘step_2’])) { $phone_default_value = $form_state[‘storage’][‘step_2’][‘phone’]; }   $form[‘step_2’] = array( ‘#type’ => ‘fieldset’, ‘#title’ => t(”), ‘#collapsible’ => false, ‘#collapsed’ => false, ); $form[‘step_2’][‘phone’] = array( ‘#type’=>’textfield’, ‘#required’ => true, ‘#title’=>t(‘Phone Number’), ‘#default_value’ => $phone_default_value, ); break; // Step 3 case 3: $city_default_value = $city_default_value = ”; if(isset($form_state[‘values’][‘step_3’])) { $street_default_value = $form_state[‘values’][‘step_3’][‘street’]; $city_default_value = $form_state[‘values’][‘step_3’][‘city’]; } elseif(isset($form_state[‘storage’][‘step_3’])) { $street_default_value = $form_state[‘storage’][‘step_3’][‘street’]; $city_default_value = $form_state[‘storage’][‘step_3’][‘city’]; }   $form[‘step_3’] = array( ‘#type’ => ‘fieldset’, ‘#title’ => t(”), ‘#collapsible’ => false, ‘#collapsed’ => false, ); $form[‘step_3’][‘street’] = array( ‘#type’=>’textfield’, ‘#required’ => true, ‘#title’=>t(‘Street Address’), ‘#default_value’ => $street_default_value, );   $form[‘step_3’][‘city’] = array( ‘#type’=>’textfield’, ‘#required’ => true, ‘#title’=>t(‘City’), ‘#default_value’ => $city_default_value, );   }     // Form Buttons $form[‘buttons’] = array ( ‘#type’ => ‘container’, ); // If we are on step 1, we do not want a back button if($form_state[‘step’] !== 1) { $form[‘buttons’][‘back’] = array ( ‘#type’ => ‘submit’, ‘#value’ => t(‘Back’), ‘#limit_validation_errors’ => array(), ‘#submit’ => array(‘ajax_multistep_form_back_submit’), ‘#ajax’ => array ( ‘wrapper’ => ‘ajax_multistep_form’, ‘callback’ => ‘ajax_multistep_form_ajax_callback’, ), ); }   if($form_state[‘step’] !== 3) { $form[‘buttons’][‘next’] = array ( ‘#type’ => ‘submit’, ‘#value’ => t(‘Next’), ‘#ajax’ => array ( ‘wrapper’ => ‘ajax_multistep_form’, ‘callback’ => ‘ajax_multistep_form_ajax_callback’, ), ); } else { $form[‘buttons’][‘submit’] = array ( ‘#type’ => ‘submit’, ‘#value’ => t(‘Submit’), ‘#ajax’ => array ( ‘wrapper’ => ‘ajax_multistep_form’, ‘callback’ => ‘ajax_multistep_form_ajax_callback’, ), ); } return $form; }

  1. Add validation for your fieldsIt will add validation for phone number field in step 2. You can add validations for other steps too.

function ajax_multistep_form_validate($form, &$form_state) { switch($form_state[‘step’]) { case “2”: $contact_phone = $form_state[‘values’][‘phone’]; $contact_errror = ‘”‘.$contact_phone .'”‘ . ‘ is not a valid North American phone number. Please enter a valid ten-digit phone number with optional extension in this format 123 456 7891.’; if (!preg_match(‘/([0-9]{3}?\s?[0-9]{3}?\s?[0-9]{4})/’, $contact_phone)) { form_set_error(‘phone’, $contact_errror); } break; } }

  1. Final submit function

function ajax_multistep_form_submit($form, &$form_state) {   $step = $form_state[‘step’];   //$form_state[‘storage’][‘step_’ . $step] = $form_state[‘step’];   if($form_state[‘step’] == 1) { $form_state[‘storage’][‘step_’ . $step][‘fname’] = $form_state[‘values’][‘fname’]; $form_state[‘storage’][‘step_’ . $step][‘lname’] = $form_state[‘values’][‘lname’];   } if($form_state[‘step’] == 2) { $form_state[‘storage’][‘step_’ . $step][‘phone’] = $form_state[‘values’][‘phone’]; }   if(isset($form_state[‘values’][‘next’]) && $form_state[‘values’][‘op’] == $form_state[‘values’][‘next’]) { // Goto next step $form_state[‘step’]++; }   if(isset($form_state[‘values’][‘back’]) && $form_state[‘values’][‘op’] == $form_state[‘values’][‘back’]) { // Goto next step $form_state[‘step’]–; } // Check if it is last step elseif(isset($form_state[‘values’][‘submit’]) && $form_state[‘values’][‘op’] == $form_state[‘values’][‘submit’]) {   $form_state[‘storage’][‘step_’ . $step][‘street’] = $form_state[‘values’][‘street’]; $form_state[‘storage’][‘step_’ . $step][‘city’] = $form_state[‘values’][‘city’];   $items = array($form_state[‘storage’][‘step_1’][‘fname’], $form_state[‘storage’][‘step_1’][‘lname’], $form_state[‘storage’][‘step_2’][‘phone’], $form_state[‘storage’][‘step_3’][‘street’], $form_state[‘storage’][‘step_3’][‘city’]); drupal_set_message(t(‘You submitted the following values:!values’, array(‘!values’ => theme(‘item_list’, array(‘items’ => $items)))));   $form_state[‘step’] = 1; $form_state[‘storage’] = array(); } $form_state[‘rebuild’] = TRUE; }

  1. Ajax callback function for every buttons in our form

function ajax_multistep_form_ajax_callback($form, &$form_state) { return $form; }

This it just an example, you store all steps value in “$form_state[‘storage’]” and use it.

$step = $form_state[‘step’]; $form_state[‘storage’][‘step_’ . $step][‘values’] = $form_state[‘values’];

Hope this helped you to get most out of the system. Feel free to share your reviews or need assistance regarding our

CakePHP development services then get in touch with us. #WeDrupalEveryday. Pick the best answer for your requirements.

ENHANCE YOUR ADMINLTE IMPLEMENT SKILLS IN LARAVEL 5

AdminLTE Implement Skills In Laravel 5
Let me walk you through AdminLTE Introduction:

  • AdminLTE is a popular open source WebApp template for admin Dashboard and control panel.It is responsive template using Bootstrap 3 and CSS framework.
  • AdminLTE is now used by thousands of users around the world.
  • AdminLTE is a based on modular design and it easily customizes and built upon.
  • This package is switched default laravel scaffolding / boilerplate to adminLTE template.
  • In laravel AdminLTE is managed by “ Bower “.

Feature of AdminLTE:

  • AdminLTE provides Sidebar mini feature to the user with the ability to collapse the sidebar without losing accessibility to side navigation.
  • Control sidebar is a new section of the layout. This sidebar use for many purposes in right sidebar
    • AdminLTE provides the 6 new skin originally. That switch the color of sidebar in dashboard.

Integrate AdminLTE:

  • If you have integrated AdminLTE so first you have to create a new project using laravel because it is easy to use and more comfortable.
  • First, You have to use laravel installer, In the terminal type the command.

composer global require “laravel/installer=~1.1”

  • Here, this command will install composer in few minutes. Then get the fresh copy of laravel using below command.

laravel new myapp

  • Here,  we create new laravel copy and its name is myapp.
  • Laravel setup is completely installed in your system then you have able to see the welcome page on your site.
  • Once, it’s process is done then after you have navigated to the public directory in a terminal command.
  • After you have navigated to the public directory you have to install AdminLTE using Bower

    bower install admin-lte

  •  Once, you have to successfully installed adminLTE in laravel then you should have folder called bower_componets and inside it you will find admin-lte.
  • Laravel is provide the greate templating system out of the box called Blade. Then after we have to convert the regular HTML page to Blade.
  • First you have to create a new blade in “ resources/view “ directory and then you have to create route for this blade.
  • If you have to create the route and blade then you will copy the “ bower_components/admin-lte/starter.html ” in new view and modify the code. Then after you will visit the page so it has blank.
  • Then after you will split the template into the three files like sidebar.blade.php, header.blade.php, footer.blade.php . so you have create new blade in view directory.
  • Then after you have create a new controller using the controller command

    php artisan make:controller TestController –plain

  • After creating controller you will do work in controller and you will create the new route for this controller

    Route::get(‘test’, ‘TestController@index‘);

  • After creating route you will check your test page so you will display the output for your developing view.

Install AdminLTE template:

  • A laravel 5 package that switch the default  Laravel scaffolding / boilerplate to adminLTE template with bootstrap 3.0.
  • AdminLTE is the so simple to install and use.
  • AdminLTE is install globally with compose

       composer global require “acacha/adminlte-laravel-installer=~2.0”

  • And convert any fresh laravel installation to AdminLTE to use with:-

    laravel new laravel-with-admin-lte cd laravel-with-admin-lte adminlte-laravel install

  • It successfully installed so you can use AdminLTE if you are use llum.
  • You are start to using AdminLTE project. Llum will be configure database (sqlite), execute migrations , install devtools and serve for you to use it.

Hope this helped you to get most out of the system. Feel free to share your reviews and need assistance for Hire Laravel Developer.

Reliable Sources To Learn About Website Testing And Be Successful

About Website Testing

Software testing is the process of reviewing a system or its component(s) to find if it completes the specified requirements or not. Testing is the process of executing a system in order to find any gaps, errors, or missing requirements in terms of the actual requirements.

In testing, a Test Scenario is what to be tested and a Test Case is how to be tested. In other words, a test scenario is a group of test cases.


Test Scenario

This is used to test  the end-to-end functionality of a software application and ensure the business processes and flows are functioning as per requirements. The tester thinks themselves as if end users and find real world scenarios (use-cases) that can be performed in testing. Once these test scenarios are completed, test cases can be written for every scenario. As Test scenarios are the concept of what to test.

Test Case

A test case is a collection of steps to be executed by the  tester team in order to validate every scenario’s. A test scenario usually has multiple test cases related with it, as test cases layout the low-level details on how to test the scenario.

Types of testing

There are different types of methods that can be used for software testing as following:

Functional testing:

  • Black box testing: In this method, it is used without having any knowledge of the internal process of the application is called black-box testing.
  • Unit testing: This kind of testing is firstly performed by developers before the actual testing given  to the testing team to formally execute the test cases for checking the functionality as per client’s requirements.
  • Integration testing: Integration testing is defined as the combination of the tested part of application to check if they function correctly or not as before.
  • Equivalence partitioning testing: In this method, set of test condition are divided into a equal partition that can be considered for example there is a range in input field like age limit, value, etc.
  • Boundary value testing: This method is used between extreme ends or boundaries between partitions of the input values for example greater than or less than some value.
  • Exploratory testing: As its name implies, it is about exploring, finding out about the software that what it does, what it doesn’t do, what works and what doesn’t work and decide with time.
  • Usability testing: Usability testing basically the testers tests the ease with which the user interfaces can be used which is user-friendly or not.
  • Design Testing: Designing testing is eye attracting & simple -through all browser & operating system(MAC,Windows & Ubuntu), with responsiveness of every page in different orientation, (add on like whatfont, page rular).
  • Functionality Testing: Functionality testing is user friendly, working as per client’s requirements- for all browser, OS & orientation & responsiveness- should work same as per requirements or functions defined as before.
  • Compatibility Testing: Compatibility testing is a type of software testing which is used to check the compatibility of the system/application/website built with various other objects such as other web browsers(IE, Firefox, Chrome, Safari), hardware platforms, users (in case if it’s very specific type of requirement, such as a user who speaks and can read only a particular language), operating systems( Mac, Windows, Ubuntu)  etc.
  • Regression Testing: Regression testing is performed to verify that a fixed bug/error hasn’t affected in another functionality/application or business rule violation of the system.

Non-functional testing:

Performance Testing: Performance testing is a non-functional testing method which is performed to determine the system parameters/requirements in terms of responsiveness and stability under various workload according to internet speed, loading time.

How does testing help businesses?
Our company’s testimonial for testing: Time to make efforts to break what we built. We QA to ensure proper standards being followed for a Quality Outcome and latest devices compatibility.

Hope this blog helps you to get the strategic idea for your testing journey. You can also refer our informative testing steps and Share your views and feedback.

How To Create Plugin In OctoberCMS Development Service

Plugin in OctoberCMS

As a name suggest “Plugin” is a software add-on (i.e. Set of code to achieve some specific functionality) that is installed
onto a program, enabling it to perform additional features.

In OctoberCMS Plugins are the foundation for adding new features to the CMS by extending it.

Purpose:

  1. To enable third-party developers to create abilities which extend an application
  2. To support easily adding new features
  3. To reduce the size of an application
  4. To separate source code from an application

To create new plugin for OctoberCMS you must have to follow below steps:

  • Registration
  • Directory Structure
  • Registration file
  • Supported methods
  • Basic plugin information
  • Routing and initialization
  • Navigation menus
  • Version History
  • Plugin version file
  • Extending with events

Registration:

The registration process allows plugins to declare their features such as components or back-end menus and pages.
Some examples of what a plugin can do:

  • Define components.
  • Define user permissions.
  • Add settings pages, menu items, lists and forms.
  • Create database table structures and seed data.
  • Alter functionality of the core or other plugins.
  • Provide classes, backend controllers, views, assets, and other files.

Directory structure: Plugins reside in the /plugins subdirectory of the application directory. An example of a plugin
directory structure:

plugins/ acme/ <=== Author name blog/ <=== Plugin name classes/ components/ controllers/ models/ updates/ … Plugin.php <=== Plugin registration file

Registration file: The Plugin.php file, called the Plugin registration file, is an initialization script that declares a plugin’s
core functions and information. Registration files can provide the following:

  • Information about the plugin, its name, and author.
  • Registration methods for extending the CMS.

Registration scripts should use the plugin namespace. The registration script should define a class with the name Plugin
that extends the \System\Classes\PluginBase class. The only required method of the plugin registration class is plug-in details.
An example Plugin registration file:

namespace Acme\Blog;   class Plugin extends \System\Classes\PluginBase { public function pluginDetails() { return [ ‘name’ => ‘Blog Plugin’, ‘description’ => ‘Provides some really cool blog features.’, ‘author’ => ‘ACME Corporation’, ‘icon’ => ‘icon-leaf’ ]; }   public function registerComponents() { return [ ‘Acme\Blog\Components\Post’ => ‘blogPost’ ]; } }

Supported methods: OctoberCMS provides list of available methods which you can define/use in your plugin

Method Name Description
pluginDetails() Returns information about the plugin.
register() Register method, called when the plugin is first registered.
boot() boot method, called right before the request route.
registerMarkupTags() Registers additional markup tags that can be used in the CMS.
registerComponents() Registers any front-end components used by this plugin.
registerNavigation() Registers back-end navigation menu items for this plugin.
registerPermissions() Registers any back-end permissions used by this plugin.
registerSettings() Registers any back-end configuration links used by this plugin.
registerFormWidgets() Registers any back-end form widgets supplied by this plugin.
registerReportWidgets() Registers any back-end report widgets, including the dashboard widgets.
registerListColumnTypes() Registers any custom list column types supplied by this plugin.
registerMailTemplates() Registers any mail view templates supplied by this plugin.
registerSchedule() registers scheduled tasks that are executed on a regular basis.

Basic plugin information: The pluginDetails is a required method of the plugin registration class.
It should return an array containing the following keys:

Key Description
name the plugin name, required.
description the plugin description, required.
author the plugin author name, required.
icon A name of the plugin icon. The full list of available icons can be found in the UI documentation. Any icon names provided by this font are valid, for example icon-glass, icon-music.
iconSvg An SVG icon to be used in place of the standard icon, optional. The SVG icon should be a rectangle and can support colors.
homepage A link to the author’s website address, optional.

Routing and initialization: Plugin registration files can contain two methods boot and register. With these methods,
you can do anything you like, like register routes or attach handlers to events.

  • register: It is called immediately when the plugin is registered.
  • boot: It is called right before a request is routed.

So if your actions rely on another plugin, you should use the boot method. For example, inside the boot method you
can extend models:

public function boot() { User::extend(function($model) { $model->hasOne[‘author’] = [‘Acme\Blog\Models\Author’]; }); }

Plugins can also supply a file named routes.php that contain custom routing logic, as defined in the router service.
For example:

Route::group([‘prefix’ => ‘api_acme_blog’], function() {   Route::get(‘cleanup_posts’, function(){ return Posts::cleanUp(); });   });

Navigation menus: Plugins can extend the back-end navigation menus by overriding the registerNavigation method
of the Plugin registration class. This section shows you how to add menu items to the back-end navigation area.

An example of registering a top-level navigation menu item with two sub-menu items:

public function registerNavigation() { return [ ‘blog’ => [ ‘label’ => ‘Blog’, ‘url’ => Backend::url(‘acme/blog/posts’), ‘icon’ => ‘icon-pencil’, ‘permissions’ => [‘acme.blog.*’], ‘order’ => 500,   ‘sideMenu’ => [ ‘posts’ => [ ‘label’ => ‘Posts’, ‘icon’ => ‘icon-copy’, ‘url’ => Backend::url(‘acme/blog/posts’), ‘permissions’ => [‘acme.blog.access_posts’] ], ‘categories’ => [ ‘label’ => ‘Categories’, ‘icon’ => ‘icon-copy’, ‘url’ => Backend::url(‘acme/blog/categories’), ‘permissions’ => [‘acme.blog.access_categories’] ] ] ] ]; }

When you register the back-end navigation you can use localization strings for the label values. Back-end navigation canalso be controlled by the permissions values and correspond to defined back-end user permissions.

Version History: It is good practice for plugins to maintain a change log that documents any changes or improvements inthe code. In addition to writing notes about changes, this process has the useful ability to execute migration and seed files in their correct order.

The change log is stored in a YAML file called version.yaml inside the /updates directory of a plugin, which co-exists
with migration and seed files.

This example displays a typical plugin updates directory structure :

plugins/ author/ myplugin/ updates/ <=== Updates directory version.yaml <=== Plugin version file create_tables.php <=== Database scripts seed_the_database.php <=== Migration file create_another_table.php <=== Migration file

Plugin version file:

1.0.1: First version
1.0.2: Second version
1.0.3: Third version
1.1.0: !!! Important update
1.1.1:

  • Update with a migration and seed
  • Create_tables.php
  • seed_the_database.php

 

As you can see above, there should be a key that represents the version number followed by the update message,
which is either a string or an array containing the update message.
Read More:- https://goo.gl/HKSrj6

Understand The Implementation of REST API In Laravel 5

In this blog, we are going to demonstrate the understanding to implement REST API in Laravel 5. Starting with some quick introduction part;
  • Rest API is backend implementing also it is a simple basic HTTP authentication to store data for different users of the application.
  • We will use the middleware to provide the authentication for the rest call.
  • The middleware will authorize the user at every request without storing in session or using token.
Implement REST API:
composer create-project restAPP –prefer-dist
  • This terminal command to we create the new application and that name is restAPP.
  • Then after we create the model for basic authentication and we are using the email for login parameter.
  • Complete the project creation after we have created the controller and model, using artisan command.
    php artisan make:model Todo
<?php 
namespace App;
 
use Illuminate\Database\Eloquent\Model;
use App\User;
 
 
class Todo extends Model {
 protected $fillable = ['title','isDone'];
    public function user(){
 
        return $this->belongsTo('App\User');
 
    }
 
}
In the model we have to add the reference to the user model and method to retrieve it.
    php artisan make:controller TodoController
<?php
namespace App\Http\Controllers;
 
use App\Http\Controllers\Controller;
use App\Todo;
use Auth;
use Request;
 
class TodoController extends Controller {
 
   /**
    * Display a listing of the resource.
    *
    * @return Response
    */
   public function index() {
 
         $todos = Todo::where('user_id','=',Auth::user()->id)->get();
     return $todos;
   }
 
   /**
    * Store a newly created resource in storage.
    *
    * @return Response
    */
   public function store() {
      $todo = new Todo(Request::all());
      $todo->user_id = Auth::user()->id;
      $todo->save();
      return $todo;
   }
 
 
}
In controller, we have to add a basic method to create and retrieve data from the logged users.
It’s all complete then we have to create a middleware to for authentication for possible to access data only if the user passes in the HTTP request his email and password. Let’s create middleware.
    php artisan make:middleware simpleAuthMiddleware
<?php namespace App\Http\Middleware;
 
use Closure;
 
class SimpleAuthMiddleware
{
 
   /**
    * Handle an incoming request.
    *
    * @param  \Illuminate\Http\Request $request
    * @param  \Closure $next
    * @return mixed
    */
   public function handle($request, Closure $next)
   {
      return Auth::onceBasic('username') ?: $next($request);
   }
 
}
After creating middleware we have to register in “ kernel.php “ file and give the key for easily use this middleware.
‘simpleauth’ => ‘App\Http\Middleware\SimpleAuthMiddleware’, After register this middleware we have to create the route path for Todo Controller and middleware
Route::get('api/todo', ['uses' => 'TodoController@index','middleware'=>'simpleauth']);
Route::post('api/todo', ['uses' => 'TodoController@store','middleware'=>'simpleauth']);
If you try with the postman on every request of email and password will be prompted. You will also pass this info on URL or HTTP header.

Hope this helped you to get most out of the system. Feel free to share your reviews or need assistance for Hire Laravel Developer then get in touch with us. Pick the best answer for your requirements.