Tag: controller

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.

Advertisements

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.