Authentication

$ npm install @nuxtjs/auth @nuxtjs/axios --save
// nuxt.config.js

modules: [
  '@nuxtjs/axios',
  '@nuxtjs/auth'
],
// nuxt.config.js

axios: {
  baseURL: 'http://homestead.project/api'
},

auth: {
  strategies: {
    local: {
      endpoints: {
        login: { url: 'login', method: 'post', propertyName: 'data.token' },
        user: { url: 'me', method: 'get', propertyName: 'data' },
        logout: false
      }
    }
  }
}
await this.$auth.loginWith('local', {
    data: {
         email: this.email,
         password: this.password
    }
 })
this.$auth.loggedIn
this.$auth.user
await this.$auth.logout();
middleware: 'auth',
https://scotch.io/tutorials/implementing-authentication-in-nuxtjs-app
https://auth.nuxtjs.org/api/auth (nuxt auth module)

Error page template

<VirtualHost *:80>
		
		ErrorDocument 404 /custom_404.html
		ErrorDocument 403 /custom_403.html
		ErrorDocument 500 /custom_50x.html
		ErrorDocument 502 /custom_50x.html
		ErrorDocument 503 /custom_50x.html
		ErrorDocument 504 /custom_50x.html

</VirtualHost>

https://www.digitalocean.com/community/tutorials/how-to-configure-apache-to-use-custom-error-pages-on-ubuntu-14-04

Disable Directory Browsing

1. Apache solution 
  a) etc/apache2/apache2.conf
  b) etc/apache2/sites-available/site.conf

<Directory /var/www/>
        Options FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

#<Directory /var/www/>
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>

2. htaccess solution 
  In directory add file: .htaccess
    Options -Indexes
3. Add index.html (simple solution)
  Sorry, the page you are looking for could not be found.

4. htaccess ignore solution
  IndexIgnore *
  IndexIgnore *.jpg

Laravel Collective – checkboxes checked

 

Example: Player groups

{{ Form::model($player, ['route'=>['players.update', $player->id], 'method'=>'PUT']) }}
    @foreach($groups as $group)
       {{ Form::checkbox('groups[]', $group->id, null, ['id' => 'group-'.$group->id] ) }}
    @endforeach
{{ Form::close() }}

run: extra help

 

Run vagrant
1. Homestead (cd users/lenovo/homestead)
2. vagrant up

configure homestead sites
1. open homestead.yaml
2.
folders:
    - map: ~/code
      to: /home/vagrant/code
3.
sites:
    - map: homestead.project
      to: /home/vagrant/code/project

4. vagrant reload --provision

5. Windows\System32\drivers\etc\hosts - 192.168.10.10  homestead.project
6. vagrant halt (shutdown vagrant)

 

Passport

https://laravel.com/docs/5.7/passport
https://tutsforweb.com/laravel-passport-create-rest-api-with-authentication/
laravel 5.5 
  composer require laravel/passport=~4.0

1. composer require laravel/passport
2. php artisan migrate
3. php artisan passport:install
1. User.php
use Laravel\Passport\HasApiTokens;
class User{
use HasApiTokens, ...
}

2. AuthServiceProvider.php
  use Laravel\Passport\Passport;
  boot(){
      Passport::routes();
  }

3. config\auth.php
  'api' => [
    'driver' => 'passport',
    'provider' => 'users'
  ]
Route::post('login', 'PassportController@login');
Route::post('register', 'PassportController@register');
Route::middleware('auth:api')->get('user', 'PassportController@details');

public function register(Request $request)
{
    $this->validate($request, [
        'name' => 'required|min:3',
        'email' => 'required|email|unique:users',
        'password' => 'required|min:6',
    ]);
 
    $user = User::create([
        'name' => $request->name,
        'email' => $request->email,
        'password' => bcrypt($request->password)
    ]);
 
    $token = $user->createToken('TutsForWeb')->accessToken;
 
    return response()->json(['token' => $token], 200);
}

public function login(Request $request)
{
    $credentials = [
        'email' => $request->email,
        'password' => $request->password
    ];
 
    if (auth()->attempt($credentials)) {
        $token = auth()->user()->createToken('TutsForWeb')->accessToken;
        return response()->json(['token' => $token], 200);
    } else {
        return response()->json(['error' => 'UnAuthorised'], 401);
    }
}

public function details()
{
    return response()->json(['user' => auth()->user()], 200);
}


public function logout(Request $request){
    $logged_out = false;		
    if (auth()->check())
        $logged_out = auth()->user()->token()->revoke();	
    $data = ['logged_out' => $logged_out];
    return response()->json($data, 200);
}

after laravel install

PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")
app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema;
function boot()
{
    Schema::defaultStringLength(200); //Solved by increasing StringLength
}