Skip to content

Instantly share code, notes, and snippets.

View sagormax's full-sized avatar
🏠
Working from home

Rashedul Islam Sagor sagormax

🏠
Working from home
View GitHub Profile
@sagormax
sagormax / DataProcessController.php
Created May 23, 2017 04:50
Laravel DataTable Server Side Processing
class DataProcessController
{
public function dataTableList(Request $request)
{
$requestData = $request->all();
$fdate = $requestData['columns'][0]['search']['value'];
$tdate = $requestData['columns'][1]['search']['value'];
$today = date('Y-m-d H:i:s');
$columns = array(
200: OK. The standard success code and default option.
201: Object created. Useful for the store actions.
204: No content. When an action was executed successfully, but there is no content to return.
206: Partial content. Useful when you have to return a paginated list of resources.
400: Bad request. The standard option for requests that fail to pass validation.
401: Unauthorized. The user needs to be authenticated.
403: Forbidden. The user is authenticated, but does not have the permissions to perform an action.
404: Not found. This will be returned automatically by Laravel when the resource is not found.
500: Internal server error. Ideally you're not going to be explicitly returning this, but if something unexpected breaks, this is what your user is going to receive.
503: Service unavailable. Pretty self explanatory, but also another code that is not going to be returned explicitly by the application.
@sagormax
sagormax / testCase.php
Last active October 8, 2018 02:12
PHPUnit Test Case Example
<?php
$user = factory(User::class)->create([
'email' => '[email protected]',
'password' => bcrypt('toptal123'),
]);
$payload = ['email' => '[email protected]', 'password' => 'toptal123'];
// 1
$this->json('POST', 'api/login', $payload)
@sagormax
sagormax / rest_api_with_transformation.php
Last active October 1, 2018 12:32
REST API with transformation
<?php
// https://www.youtube.com/watch?v=zST3gGvnoww
//https://medium.com/@dinotedesco/laravel-api-resources-what-if-you-want-to-manipulate-your-models-before-transformation-8982846ad22c
// Routes
$app->get('products', 'ProductsController@index');
$app->get('products/{id}', 'ProductsController@show');
$app->put('products/{id}', 'ProductsController@update');
$app->post('products', 'ProductsController@store');
FROM php:7.0.4-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
{
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
"version": "1.0.0",
"title": "Swagger Petstore",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"email": "[email protected]"
},
@sagormax
sagormax / convert_header.php
Created March 6, 2019 05:25
Convert headers to Japanese. Here is a process of rewriting from [PATTERN] below to [TO STRING]
<?php
$strCsvFilePath = DIR_CSV . $strCsvFileName; // SaveDir
$strCsvDownloadUrl = URL_HOST . 'csv/' . $strCsvFileName; // Download Url
mb_language("Japanese");
// Header
$strCsvFileText = file_get_contents($strCsvFilePath);
$from_encoding = CSV_ENCODE_AFTER;
@sagormax
sagormax / app.php
Created March 6, 2019 05:27
Laravel 5 single log file name change
<?php
# CUSTOM DAILY LOG
// $app->configureMonologUsing(function($monolog) use ($app) {
// $monolog->pushHandler(
// (new Monolog\Handler\RotatingFileHandler(
// // Set the log path
// $app->storagePath().'/logs/app_error.log',
// // Set the number of daily files you want to keep
// $app->make('config')->get('app.log_max_files', 30)
// ))->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true))
@sagormax
sagormax / BasicAuthMiddleware.php
Created March 12, 2019 10:26
BasicAuthMiddleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
/**
* Basic Auth / Basic認証の処理
*/
@sagormax
sagormax / AbstructApi.js
Created October 17, 2019 04:49
JavaScript Abstruct API
import { BASE_PATH, RESPONSE_OK } from '../../constants/Api';
import axios from 'axios';
export default class AbstractApi {
constructor() {
this.api = axios;
this.path = '';
this.data = {};
}