Skip to content

Instantly share code, notes, and snippets.

Avatar

Farindra farindra

View GitHub Profile
@farindra
farindra / SetLocale.php
Last active Apr 21, 2021
Laravel Middleware - Set Locale from request and session
View SetLocale.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class SetLocale
{
/**
@farindra
farindra / swagger.yaml
Created Apr 11, 2021
Lumen Jwtauth Part 1 - Swagger Version 1.0
View swagger.yaml
openapi: 3.0.3
info:
title: Lumen JWT Auth
version: '1.0'
contact:
email: farindra.project@gmail.com
name: Farindra
url: 'https://farindra.com'
license:
name: MIT license
@farindra
farindra / MovieCRUDTest.php
Last active Apr 11, 2021
Lumen Jwtauth Part 1 - Test Movie CRUD
View MovieCRUDTest.php
<?php
use App\Models\Movie;
use Illuminate\Support\Facades\Artisan;
use Laravel\Lumen\Testing\DatabaseMigrations;
class MovieCRUDTest extends TestCase
{
use DatabaseMigrations;
@farindra
farindra / CorsMiddleware.php
Last active Apr 11, 2021
Lumen Jwtauth Part 1 - Cors Middleware
View CorsMiddleware.php
<?php
namespace App\Http\Middleware;
use Closure;
class CorsMiddleware
{
/**
* Handle an incoming request.
@farindra
farindra / UserAuthTest.php
Last active Apr 11, 2021
Lumen Jwtauth Part 1 - Test User Auth
View UserAuthTest.php
<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
class UserAuthTest extends TestCase
{
use DatabaseMigrations;
/**
* user token
@farindra
farindra / Handler.php
Created Apr 4, 2021
Lumen Jwtauth Part 1 - Error Handler
View Handler.php
public function render($request, Throwable $exception)
{
/* only run if debug is turn off */
if ( !env('APP_DEBUG', true) ) {
/* handling 404 exception */
if($exception instanceof NotFoundHttpException){
return response()->json([
'error' => 'Not Found',
@farindra
farindra / MovieController.php
Created Apr 4, 2021
Lumen Jwtauth Part 1 - Movie Controller
View MovieController.php
<?php
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class MovieController extends Controller
{
@farindra
farindra / movie.php
Last active Apr 12, 2021
Lumen Jwtauth Part 1 - Movie Route
View movie.php
<?php
/* movie group */
$router->group(['prefix' => 'movie', 'as' => 'movie'], function () use ($router) {
/* all movies */
$router->get('/all', [ 'as' => 'all', 'uses' => 'MovieController@all']);
/* show movies by id */
$router->get('/{id}', [ 'as' => 'show', 'uses' => 'MovieController@show']);
@farindra
farindra / AuthController.php
Last active Apr 12, 2021
Lumen Jwtauth Part 1 - Auth Controller
View AuthController.php
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class AuthController extends Controller
@farindra
farindra / UserRegistration.php
Last active Apr 7, 2021
Lumen Jwtauth Part 1 - Test User Registration
View UserRegistration.php
<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Artisan;
use app\Libraries\Core;
class UserRegistrationTest extends TestCase
{
use DatabaseMigrations;