PHP code example of stockraken / response

1. Go to this page and download the library: Download stockraken/response library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stockraken / response example snippets




namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Stockraken\Response\Response as skresponse; // menggunakan alias skresponse, anda bisa mengubah alias sesuai keinginan anda

class PassportController extends Controller
{

    public function contoh()
    {
    }

}
 



namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Stockraken\Response\Response as skresponse; // menggunakan alias skresponse, anda bisa mengubah alias sesuai keinginan anda

class PassportController extends Controller
{

    public function contoh()
    {
        $ar = array(
            "contohdata" => "contoh isi data",
            "nilai" => 123,
            "test" => [1,2,3,4,5,9,10]
        );
        
        skresponse::$status = true; // status response terserah anda bisa true/false atau 'ok'/'no'
        skresponse::$message= "Berhasil ambil data"; // pesan yang akan ditampilkan pada response
        skresponse::$code   = 200; // kode response header, misal 200 untuk sukses, 404 untuk data tidak ditemukan, 501 untuk server error dll
        skresponse::$data   = $ar; // set data ke response
        
        return skresponse::run(); // mengmebalikan nilai
    }

}
 

Route::get('contoh', 'PassportController@contoh');