PHP code example of parsgit / night

1. Go to this page and download the library: Download parsgit/night 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/ */

    

parsgit / night example snippets



// input all params
$all = input();

// sample
$name = input('name');

$name = input('name','default_value_if_not_exists');


// get Requests
$name = get('name','Default value');

// post Requests
$name = post('name');
$age = post('age',18);

root_path();   // root project directory path
public_path(); // public directory path
app_path();    // app directory path
storage_path(); // storage directory path
views_path();   // views directory path

$app_path=app_path('Storage/text.txt');

echo $app_path; 
//output sample : var/www/site/html/app/Storage/text.txt

url();// yoursite.com
url('account/login'); // yoursite.com/account/login

$route=route_url();
//output: account/login

$route=params_url();
// output array:['account','login']

//Returns the REQUEST METHOD type
$request = method();  // POST or GET

//If the REQUEST METHOD of the get type returns true
if(isGet()){
  // code
}

//If the REQUEST METHOD of the post type returns true
if(isPost()){
  // post
}



namespace Controllers;

class pageController{

  // yoursite.com/page
  function Action(){
    return view('html_name');
  }

  // yoursite.com/page/id
  function idAction(){
   $id=get('id',0);
   return $id;
  }
}


$users=DB::select('select * from users where active=?',[true]);

DB::insert('insert into users (name,age,username,password) values (?,?,?,?)',
[
'ben',
25,
'ben25',
Hash::create('123456')
]);

DB::update('...');
DB::delete('...');




namespace Controllers;
use App\Web\DB;

class pageController{

  // yoursite.com/page/get-list
  function get_listAction(){
  
   $pages=DB::table('page')->get();
   return $pages;
   
  }
}

$user = DB::table('users')->where('name', 'John')->first();
echo $user->name;

// ⇒ find user by id field
$user = DB::table('users')->find(20);

//support other functions:
// where / orWhere
// whereBetween / orWhereBetween
// whereNotBetween / orWhereNotBetween
// whereIn / whereNotIn / orWhereIn / orWhereNotIn
// whereNull / whereNotNull / orWhereNull / orWhereNotNull
// whereDate / whereMonth / whereDay / whereYear / whereTime
// whereColumn / orWhereColumn

$first = DB::table('users')
            ->whereNull('first_name');

$users = DB::table('users')
            ->whereNull('last_name')
            ->union($first)
            ->get();

// ⇒ get count users list
$count_users = DB::table('users')->count(); // return int

// ⇒ get count users list
$score = DB::table('users')->sum(`score`); // return int

// => join
$users = DB::table('users')
            ->join('car', 'users.id=car.user_id')
            ->get();

// => left Join
$users = DB::table('users')
            ->leftJoin('posts', 'users.id=posts.user_id')
            ->get();

// right join
$users = DB::table('users')
            ->rightJoin('posts', 'users.id=posts.user_id')
            ->get();
       
  // full Join
$users = DB::table('users')
            ->fullJoin('posts', 'users.id=posts.user_id')
            ->get();

$users = DB::table('users')
                ->orderBy('name', 'desc')
                ->get();

$user = DB::table('users')
                ->latest()
                ->first();

$randomUser = DB::table('users')
                ->inRandomOrder()
                ->first();

$users = DB::table('users')
                ->groupBy('account_id')
                ->having('account_id', '>', 100)
                ->get();

$users = DB::table('users')
                ->groupBy('first_name', 'status')
                ->having('account_id', '>', 100)
                ->get();

$users = DB::table('users')
                ->duplicate('phone', 2)
                ->get();

$users = DB::table('users')->skip(10)->take(5)->get();

$users = DB::table('users')
                ->offset(10)
                ->limit(5)
                ->get();

DB::table('users')->insert(
    ['email' => 'john@example.com', 'votes' => 0]
);

DB::table('users')
            ->where('id', 1)
            ->update(['votes' => 1]);

DB::table('users')->increment('votes');

DB::table('users')->increment('votes', 5);

DB::table('users')->decrement('votes');

DB::table('users')->decrement('votes', 5);

DB::table('users')->delete();

DB::table('users')->where('votes', '>', 100)->delete();

DB::table('users')->truncate();


namespace Controllers;

use App\Web\File;

class fileController{

  // yoursite.com/file/upload
  function uploadAction(){
   $upload=File::upload('myfile');
  }
}

$upload->path(public_path('imge'));

$upload->toStorage('image/products');

$upload->maxSize(250); // limit max size 250 kb 

$upload->maxSize(3 * 1023); // limit max size 3 mg

$upload->limit_ext(['jpg','png','gif']);

$upload->limit_type(['image/jpage']);

$uplaod->rename('my_file_name');

// or change custom file extension
$uplaod->rename('my_file_name','pngo');//my_file_name.pngo

$upload->randomName();

$upload->save();


namespace Controllers;

use App\Web\File;

class fileController{

  // yoursite.com/file/upload
  function uploadAction(){
  
   $upload=File::upload('myfile')
   ->limit_ext(['png','jpg'])
   ->maxSize(1024)      //1 mg
   ->toStorage('image') //Storage/image directory
   ->save();            // save file
	
	if($upload->status()==true){
		// Upload Is Done :)
		return['upload'=>true,'name'=>$upload->getFileName()];
	}
	else{
		// Upload Is Failed :(
		$errors=$upload->getErrors();
		return['upload'=>false,'errors'=>$errors];
	}
  }
}

 if($upload->status()==true){
	 //Code ...
 }

$upload->getErrors();