1. Go to this page and download the library: Download fort/php 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/ */
fort / php example snippets
nv\Dotenv::createImmutable(__DIR__)->load();
use Fort\PHP\Support\DB;
DB::connect();
// PDO Object: connected
use Fort\PHP\Support\DB;
use Carbon\Carbon;
DB::insert('users', [
'name'=> 'Phil Everette',
'email'=> '[email protected]',
'phone'=> '0205550368',
'created_at'=> Carbon::now() // fort/php already ships with carbon
]);
// @return (bool) true, false otherwise
use Fort\PHP\Support\DB;
use Carbon\Carbon;
DB::update('users', 1, [
'name'=> 'Sam Everette',
'email'=> '[email protected]',
'phone'=> '0205550368',
'created_at'=> Carbon::now()
]);
// 1 is the id of the record to update
// @return (bool) true, false otherwise
use Fort\PHP\Support\DB;
public function createInvoice()
{
try
{
DB::beginTransaction();
//start some database queries
DB::commit();
// commit the queries
}
catch (Exception $exception)
{
DB::rollBack();
// rollback the transaction in case of error
}
}
use Fort\PHP\Support\DB;
$unpaidOrders = DB::table('orders')
->where('payment_status', '=', 'unpaid')
->orderBy('id', 'desc')
->get();
foreach ($unpaidOrders as $item){
echo $item['amount'];
}
use Fort\PHP\Support\DB;
$items = DB::rawQuery("SELECT users.id FROM users,
INNER JOIN orders ON users.id = orders.user_id")->get();
foreach ($items as $item){
// echo ... ;
}
use Fort\PHP\Support\DB;
$adult = DB::table('users')
->select(['name', 'age'])
->where('age', '>', 18)
->orderBy('id', 'desc')
->get();
foreach ($adult as $individual){
echo $individual['age'];
}
use Fort\PHP\Support\DB;
DB::table('invoices')->all();
// @returns all invoices
use Fort\PHP\Support\DB;
DB::table('users')->where('email', '=','[email protected]')->first();
// @returns the record in the query set
use Fort\PHP\Support\DB;
DB::table('invoices')->where('amount_paid', '<', 1)->get();
use Fort\PHP\Support\DB;
DB::table('invoices')->where('amount_paid', '<', 1)
->orWhere('amount_paid', '=', false)
->get();
use Fort\PHP\Support\DB;
DB::table('invoices')->sum('amount_paid');
// @returns (int|float) a sum of the specified column
use Fort\PHP\Support\DB;
DB::table('orders')->count();
// @returns total number of orders
use Fort\PHP\Support\DB;
DB::table('invoices')->max('amount');
// @returns (int|float) the highest number in the column
use Fort\PHP\Support\DB;
DB::table('invoices')->min('amount');
// @returns (int|float) the smallest number in the column
use Fort\PHP\Support\Http;
Http::post('https://api.velstack.com/send',[$data],
["Accept" => "application/json", "Authorization" => "Bearer API_KEY}"];
use Fort\PHP\Str;
$haystack = array('FORT', 'Everette', 'Mike');
// returns true if the needle exist in case insensitive, false otherwise
Str::valueExist($haystack, 'foRT');
// true
use Fort\PHP\Str;
$slice = Str::contains('I was raised in Ghana', 'Ghana');
// 'true'
use Fort\PHP\Str;
$string = Str::containsAll('My dad is from UK but i live in the US', ['UK', 'US']);
// 'true'
use Fort\PHP\Str;
$slice = Str::after('His name is fort', 'His name');
// ' is fort'
use Fort\PHP\Str;
$slice = Str::afterLast('app\Http\Controllers\Controller', '\\');
// 'Controller'
use Fort\PHP\Str;
$slice = Str::before('He is married', 'married');
// 'He is'
use Fort\PHP\Str;
$slice = Str::beforeLast('He is married', 'is');
// 'He'
use Fort\PHP\Str;
$slice = Str::between('He was born in March', 'He', 'March');
// 'was born in'
use Fort\PHP\Str;
$string = 'Transporter is a brilliant !';
$replaced = Str::replace('brilliant', 'genius', $string);
// Transporter is a genius !
use Fort\PHP\Str;
$string = 'Transporter !';
$char = Str::charAt($string, 3);
// t
use Fort\PHP\Str;
$string = 'Everette is 1 year old';
$string = Str::endsWith($string, 'old');
// true
use Fort\PHP\Str;
$string = 'Everette is 1 year old';
$string = Str::finish($string, '!');
// Everette is 1 year old!