JWT Laravel Auth..

 App/Http/Kernel.php


 protected $routeMiddleware = [

      

'jwt.healthpro' => \App\Http\Middleware\Healthpro::class,

'jwt.Clientmiddleware' => \App\Http\Middleware\Clientmiddleware::class,

    ];


Api.php

 Route::group(['middleware' => ['jwt.healthpro']], function() {

    Route::any('/get_state_list', [App\Http\Controllers\Userapis::class, 'get_state_list']);

    Route::post('/get_city_list',[App\Http\Controllers\Userapis::class, 'get_city_list']);


});


Controller.php

<?php

namespace App\Http\Controllers;


use Illuminate\Foundation\Auth\Access\AuthorizesRequests;


use Illuminate\Foundation\Bus\DispatchesJobs;


use Illuminate\Foundation\Validation\ValidatesRequests;


use Illuminate\Routing\Controller as BaseController;


use Validator;

use Carbon\Carbon;

use DB;


use Illuminate\Support\Facades\Auth;


use App\Models\User;

use App\Models\Client;

use App\Models\Professional;

use App\Models\Profession;

use App\Models\Coupons;

use App\Models\Blog;

use Illuminate\Http\Request;

use App\Models\Welcome;

use Illuminate\Support\Str;

use Illuminate\Support\Arr;

use Session;

use JWTAuth;

use Tymon\JWTAuth\Exceptions\JWTException;

class Userapis extends Controller {

 public function get_state_list(Request $request) {

     $state = DB::table('states')->select('*')->where('countryid','231')->get();

      

    return response()->json([

            'message' => 'Data',

            'state' => $state

        ], 201);

}

public function get_city_list(Request $request) {

   $data = DB::table('city')->select('*')->where('state_id',$request->input('id'))->get();

       $array=array('status'=>200,'message'=>'Data get!','data'=>$data);

    return response()->json([

            'message' => 'Data',

            'city' => $data

        ], 201);

}

}

?>



Model

<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Foundation\Auth\User as Authenticatable;

use Illuminate\Notifications\Notifiable;

use Laravel\Passport\HasApiTokens;

use Tymon\JWTAuth\Contracts\JWTSubject;


class User extends Authenticatable implements JWTSubject

{

    use HasFactory, Notifiable;


    /**

     * The attributes that are mass assignable.

     *

     * @var array

     */

    protected $fillable = [

        'name',

        'email',

        'password',

    ];


    /**

     * The attributes that should be hidden for arrays.

     *

     * @var array

     */

    protected $hidden = [

        'password',

        'remember_token',

    ];


    /**

     * The attributes that should be cast to native types.

     *

     * @var array

     */

    protected $casts = [

        'email_verified_at' => 'datetime',

    ];

public function getJWTIdentifier() {

        return $this->getKey();

    }


    /**

     * Return a key value array, containing any custom claims to be added to the JWT.

     *

     * @return array

     */

    public function getJWTCustomClaims() {

        return [];

    }   

}


?>



Auth.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    |
    | This option controls the default authentication "guard" and password
    | reset options for your application. You may change these defaults
    | as required, but they're a perfect start for most applications.
    |
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session", "token"
    |
    */

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

        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
            'hash' => false,
        ],
'clientapi' => [
            'driver' => 'jwt',
            'provider' => 'client',
            'hash' => false,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
'client' => [
            'driver' => 'eloquent',
            'model' => App\Models\Client::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    |
    | You may specify multiple password reset configurations if you have more
    | than one user table or model in the application and you want to have
    | separate password reset settings based on the specific user types.
    |
    | The expire time is the number of minutes that the reset token should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
            'throttle' => 60,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Password Confirmation Timeout
    |--------------------------------------------------------------------------
    |
    | Here you may define the amount of seconds before a password confirmation
    | times out and the user is prompted to re-enter their password via the
    | confirmation screen. By default, the timeout lasts for three hours.
    |
    */

    'password_timeout' => 10800,

];
?>






Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.