Friday, May 5, 2017

What are the main differences between Laravel 4 and Laravel 5.x?

Summarizing Laravel 5.0 Release notes from the above article:

 1. The old app/models directory has been entirely removed.
2. Controllers, middleware, and requests (a new type of class in Laravel 5.0) are now grouped under the app/Http directory.
3. A new app/Providers directory replaces the app/start files from previous versions of Laravel 4.x.
4. Application language files and views have been moved to the resources directory.
5. All major Laravel components implement interfaces which are located in the illuminate/contracts repository.
6. New route:cache Artisan command to drastically speed up the registration of your routes.
7. Laravel 5 now supports HTTP middleware, and the included authentication and CSRF "filters" have been converted to middleware.
8. you may now type-hint dependencies on controller methods.
9. User registration, authentication, and password reset controllers are now included out of the box, as well as simple corresponding views, which are located at resources/views/auth.
10. You may now define events as objects instead of simply using strings.
11. In addition to the queue job format supported in Laravel 4, Laravel 5 allows you to represent your queued jobs as simple command objects. These commands live in the app/Commands directory.
12. A database queue driver is now included in Laravel, providing a simple, local queue driver that requires no extra package installation beyond your database software.
13. Laravel command scheduler allows you to fluently and expressively define your command schedule within Laravel itself, and only a single Cron entry is needed on your server.
14. The php artisan tinker command now utilizes Psysh by Justin Hileman, a more robust REPL for PHP.
15. Laravel 5 now utilizes DotEnv by Vance Lucas.
16. Laravel Elixir, by Jeffrey Way, provides a fluent, expressive interface to compiling and concatenating your assets.
17. Laravel Socialite is an optional, Laravel 5.0+ compatible package that provides totally painless authentication with OAuth providers.
18. Laravel now includes the powerful Flysystem filesystem abstraction library, providing pain free integration with local, Amazon S3, and Rackspace cloud storage - all with one, unified and elegant API!
19. Laravel 5.0 introduces form requests, which extend the Illuminate\Foundation\Http\FormRequest class. These request objects can be combined with controller method injection to provide a boiler-plate free method of validating user input.
20. The Laravel 5 base controller now includes a ValidatesRequests trait. This trait provides a simple validate method to validate incoming requests.
21. new Artisan generator commands have been added to the framework.
22. The popular dd helper function, which dumps variable debug information, has been upgraded to use the amazing Symfony VarDumper.

Friday, April 28, 2017

CURD Operation index.blade.php

@extends('adminlte::page')

@section('title', 'Subscriptions')

@section('content_header')
    <h1>Subscriptions</h1>
@stop

@section('content')

<!-- @foreach($subscriptions as $subscription)

<li>{!! $subscription['subscription_name'] !!}
{!! $subscription['subscription_description'] !!}
{!! $subscription[' subscription_type'] !!}</li>
@endforeach -->


@if(Session::has('message'))
<div class='alert alert-success'>{{Session::get('message')}}</div>
@endif

 <div class="col-sm-2">
<!-- <tr>
<td> -->
<a type="button" href="{{ url('admin/subscriptions/create') }}" class="btn btn-block btn-primary">Add Subscriptions</a>
<!-- </td></tr>-->
 </div>
<section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Total {{$subscriptions->total()}} Records</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example2" class="table table-bordered table-hover">
                <thead>
                <tr>
                  <th>Sr. No.</th>
                  <th>Name</th>
                  <th>Description</th>
                  <th>Price</th>
                  <th>Days</th>
                  <th>Plan Type</th>
                  <th>Created Date</th>
                  <th>Actions</th>
                </tr>
                </thead>
                <tbody>               
              
                 @foreach($subscriptions as $subscription)
                  <tr>
                 
                  <td>{!! $subscription['id'] !!}</td>
                  <td>{!! $subscription['subscription_name'] !!}</td>
                  <td>{!! $subscription['subscription_description'] !!}</td>
                  <td>{!! $subscription['subscription_price'] !!}</td>
                  <td>{!! $subscription['days'] !!}</td>
                  <td>{!! $subscription['subscription_type'] !!}</td> 
                  <td>{!! $subscription['created_at'] !!}</td> 
                  <td>
                  <div class="btn-group">
                  <button type="button" class="btn btn-success">Action</button>
                  <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown">
                    <span class="caret"></span>
                    <span class="sr-only">Toggle Dropdown</span>
                  </button>
                  <ul class="dropdown-menu" role="menu">
                   <!--  <li><a href="{{ url('admin/subscriptions/create') }}">Add Subscriptions</a></li> -->
                    <li><a href="{{ route('subscriptions.edit', $subscription['id']) }}">Edit</a></li>
                    <li><a href="{{ url('admin/subscriptions/deleterecord', $subscription['id']) }}">Delete</a></li>
                    <!--   <li><a href="#">Inactive</a></li> -->
                    <!-- <li class="divider"></li> -->             
                    <li><a href="{{ url('admin/subscriptions',$subscription['id']) }}">View</a></li>
                  </ul>
                </div>
                  </td>
                  </tr>    
                  @endforeach

                </tfoot>
              </table>
              {{$subscriptions->links()}}
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->


          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->



@stop

@section('css')
    <link rel="stylesheet" href="/css/admin_custom.css">
@stop

@section('js')
    <script> console.log('Hi!'); </script>
@stop


CURD operation create.blade.php

@extends('adminlte::page')

@section('title', 'Subscriptions')

@section('content_header')
   
@stop

@section('content')


   


 <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">Add Subscriptions Plan</h3>
            </div>
           
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
    <li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
            <!-- /.box-header -->
            <!-- form start -->
          
{!! Form::open(array('route' => 'subscriptions.store','class' => 'form','id' => 'createinspector','name' => 'createinspector','files' => true)) !!}
{!! csrf_field() !!}
              <div class="box-body">

                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Name</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" name="subscription_name" placeholder="Name">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Description</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" name="subscription_description" placeholder="Description">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Plan Type</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" name="subscription_type" placeholder="Plan Type">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Price</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" name="subscription_price" placeholder="Price">
                  </div>
                </div>
             
                 <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Days</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" name="days" placeholder="Days">
                  </div>
                </div>

              
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <a type="submit" class="btn btn-default" href="{{ url('admin/subscriptions/') }}">Cancel</a>
                <button type="submit" class="btn btn-info pull-right">Submit</button>
              </div>
              <!-- /.box-footer -->
               
{!! Form::close() !!}
          </div>
          <!-- /.box -->




@stop

@section('css')
    <link rel="stylesheet" href="/css/admin_custom.css">
@stop

@section('js')
    <script> console.log('Hi!'); </script>
@stop




CURD operation edit.blade.php Code

@extends('adminlte::page')

@section('title', 'Subscriptions')

@section('content_header')
   
@stop

@section('content')


 <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">Edit Subscriptions Plan</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
          
{!! Form::open(array('route' => ['subscriptions.update', $subscriptions->id],'class' => 'form','method' => 'put','name' => 'createinspector','files' => true)) !!}
{!! csrf_field() !!}
              <div class="box-body">

                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Name</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="{{old('subscription_name', $subscriptions->subscription_name) }}" name="subscription_name" placeholder="Name">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Description</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="{{old('subscription_description',$subscriptions->subscription_description) }}" name="subscription_description" placeholder="Description">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Plan Type</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="{{old('subscription_type', $subscriptions->subscription_type) }}" name="subscription_type" placeholder="Plan Type">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Price</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="{{old('subscription_price', $subscriptions->subscription_price) }}" name="subscription_price" placeholder="Price">
                  </div>
                </div>
             
                 <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Days</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="{{old('days', $subscriptions->days) }}" name="days" placeholder="Days">
                  </div>
                </div>

              
              </div>
              <!-- /.box-body -->
              <div class="box-footer button-group">
              <div class="col-sm-3"></div>
              <div class="col-sm-3">
                <button type="submit" class="btn btn-default" href="{{ url('admin/subscriptions/') }}">Cancel</button>
                <button type="submit" class="btn btn-info pull-right">Update</button>
              </div>            
              </div>
              <!-- /.box-footer -->
               
{!! Form::close() !!}
          </div>
          <!-- /.box -->




@stop

@section('css')
    <link rel="stylesheet" href="/css/admin_custom.css">
@stop

@section('js')
    <script> console.log('Hi!'); </script>
@stop




CURD Operation Controller & Routes Code

web.php
*******************
Route::resource('admin/subscriptions', 'SubscriptionController');
Route::resource('admin/subscriptions/deleterecord', 'SubscriptionController@deleterecord');

 SubscriptionController.php Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Subscription;
use DB;

class SubscriptionController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $subscriptions = Subscription::paginate(4);
        //$users = json_decode(json_encode($users),true);      
        return view('subscriptions.index', ['subscriptions' => $subscriptions]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('subscriptions.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
      
        $this->validate($request, [
        'subscription_name' => 'required ',
        'subscription_description' => 'required | min:10',
        'subscription_type' => 'required',
        'subscription_price' => 'required',
        'days' => 'required',
       
        ]);

        Subscription::create($request->all());

       // Session::flash('flash_message','Subscription successfully added.');

       // return redirect()->action('SubscriptionController@index');     
        return redirect()->route('subscriptions.index')->with('message','Subscriptions has been added successfully.');
      
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $subscriptions = Subscription::find($id);
        return view('subscriptions.show', ['subscriptions' => $subscriptions]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $subscriptions = Subscription::find($id);
       // return $subscriptions;
        return view('subscriptions.edit')->with('subscriptions',$subscriptions);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
       
        Subscription::find($id)->update($request->all());

        return redirect()->route('subscriptions.index')
                        ->with('message','Subscription updated successfully');
       
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $subscriptions = Subscription::find($id);
        $subscriptions->delete();
        return redirect()->route('subscriptions.index');
    }
    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function deleterecord($id)
    {
        $subscriptions = Subscription::find($id);
        $subscriptions->delete();
        return redirect()->route('subscriptions.index')
                        ->with('message','Subscription Deleted successfully');;
    }
}

What are the main differences between Laravel 4 and Laravel 5.x?

Summarizing Laravel 5.0 Release notes from the above article:  1. The old app/models directory has been entirely removed. 2. Controllers...