Categories
Laravel

Tutorial – How to do a search form with laravel pagination bootstrap ?

Define routes at routes/web.php

//All certificates
Route::post('/search-certificates', 'CertificatesController@search' );
Route::get('/search-certificates', 'CertificatesController@search' );
or
Route::any('/search-certificates', 'CertificatesController@search' );

Define Controller function Search

public function search(Request $request){
    $searchString = $request->input('searchString');
    $searchCertificates = DB::table('NAMEOFYOURBABLE')
        ->where('BOROUGH', 'like', "%$searchString%" )
        ->orwhere('STREET', 'like', "%$searchString%" )
        ->orwhere('POSTCODE', 'like', "%$searchString%" )
        ->orderBy('POSTCODE', 'asc')
        ->orderBy('NUMBER', 'asc')
        ->orderBy('JOB_NUMBER', 'asc')
        ->paginate(20);

    $searchCertificates->appends(['searchString' => $searchString]);

    return view('search-certificates', ['searchCertificates' => $searchCertificates]);
}

Most important line on the code above is the one below because it will allow search pagination

    $searchCertificates->appends(['searchString' => $searchString]);

Define View Laravel Blade Page

Form

<form action="/search-certificates" method="POST" role="search">
    {{ csrf_field() }}
    <div class="input-group">
        <input type="text" class="form-control" name="searchString"
               placeholder="Search by Street or Postal Code " />
         <button type="submit" class="btn btn-primary">Submit</button>
    </div>
</form>

Grid/Table

<div class="row justify-content-center">
<table class="table table-striped">
<thead>
<tr>
<th>POSTCODE</th>
<th>ISSUE_TYPE</th>
<th>C_O_ISSUE_DATE</th>
<th>BOROUGH</th>
<th>NUMBER</th>
<th>STREET</th>
<th>Number of Units</th>
<th>NTA</th>
</tr>
</thead>
<tbody>
@foreach ($searchCertificates as $oneCertificate)
<tr>
<td>{{ $oneCertificate->POSTCODE }}</td>
<td>{{ $oneCertificate->ISSUE_TYPE }}</td>
<td>{{ $oneCertificate->C_O_ISSUE_DATE }}</td>
<td> {{ $oneCertificate->BOROUGH }}</td>
<td>{{ $oneCertificate->NUMBER }}</td>
<td>{{ $oneCertificate->STREET }}</td>
<td>{{ $oneCertificate->PR_DWELLING_UNIT }}</td>
<td>{{ $oneCertificate->NTA }}</td>
</tr>
@endforeach
</tbody>

Blade Pagination Link

{{ $searchCertificates->links( "pagination::bootstrap-4") }}
Categories
Laravel

Tutorial Install Oauth2 Server

Find below the steps to install an Oauth2 server with laravel Passport

Install the package

composer require laravel/passport
php artisan migrate
php artisan passport:install

Retrieve the keys from laravel passport

Personal access client created successfully.
 Client ID: 7
 Client secret: JfTAiRtvsdX2pZI1cBUShCrd2BU5pYYrX0lzHwRhBq
 Password grant client created successfully.
 Client ID: 8
 Client secret: Y3nUHg1xcaOPCsdsdsqbIjA3Ghj5CJnTf0pD1p3t2U5wN

Modify App\User.php file

<?php namespace App;
 use Laravel\Passport\HasApiTokens; 
use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 

class User extends Authenticatable {    
 use HasApiTokens, Notifiable; 
}

Register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens:

<?php namespace App\Providers; 
use Laravel\Passport\Passport;
 use Illuminate\Support\Facades\Gate;
 use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; 

class AuthServiceProvider extends ServiceProvider {  
   /**      
    * The policy mappings for the application.      
    *     
    * @var array      
    */     
     protected $policies = [  
       'App\Model' => 'App\Policies\ModelPolicy',   
      ];    
 /**      
   * Register any authentication / authorization services.      
   *
   * @return void     
   */  
   public function boot()     
   {
      $this->registerPolicies();   
      Passport::routes();    
   } 
}

Configure config/auth.php

'guards' => [     
         'web' => [         
                   'driver' => 'session',
                   'provider' => 'users',
           ],
         'api' => [         
                   'driver' => 'passport',
                   'provider' => 'users',    
                ],
 ],

SET TO GO, now get access token to proceed

Use the generated key in initial step called Password grant client

Categories
Laravel

Tutorial – Laravel 6 – Create Login Page

composer require laravel/ui 
php artisan ui vue --auth 
npm install && npm run dev
php artisan migrate

See the routes created

php artisan route:list

Categories
Laravel

How to fix laravel failed loading cafile stream: `/usr/local/etc/openssl/cert.pem’ ?

Ho to fix laravel failed loading cafile stream: `/usr/local/etc/openssl/cert.pem’ ?

In your mac execute the following command

brew reinstall wget
Categories
Queues REDIS

How to resolve laravel Connection refused [tcp://127.0.0.1:6379] ?

#1 inst all Redis on your mac as follow

brew install redis

Launch Redis on computer starts.

$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

Start Redis server via “launchctl”.

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Start Redis server using configuration file.

$ redis-server /usr/local/etc/redis.conf

Stop Redis on autostart on computer start.

$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Location of Redis configuration file.

/usr/local/etc/redis.conf

Uninstall Redis and its files.

$ brew uninstall redis
$ rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Get Redis package information.

$ brew info redis

Test if Redis server is running.

$ redis-cli ping
Categories
API

API Collection

Symfony

Laravel

Lumen

Raleche Framework