π’ Let's build together by not reinventing the wheel but assembling the wheels to reinvent a new π
πΉ First install composer globally(if you don't have it) by running the following commands
For Ubuntu
curl -sS https://getcomposer.org/installer | php && sudo mv composer.phar /usr/local/bin/composerFor Cent OS
curl -sS https://getcomposer.org/installer | php && chmod +x composer.phar && sudo mv composer.phar /usr/local/bin/composerπΉ Then install Elham by the following command(for latest stable releases)
composer create-project chandan07cse/elham YOUR_PROJECT_NAMEπΉ But if you want Elham from its master branch, then you could certainly type it
composer create-project chandan07cse/elham=dev-master YOUR_PROJECT_NAMEπΉ Now cd into your_project_name/public & run by the php command
cd YOUR_PROJECT_NAME/public
php -S localhost:8000πΉ Note : For the rest of the project we'll run each & every command from the project directory. For that
cd ../πΉ To check the list of dependencies Elham relies, run the command
composer info- To check the visual dependencies, please go to the link Visual Dependecies
πΉ Let's run the below command to run elham command if you are in Linux
echo "alias elham='./elham'" >> ~/.bash_aliases && source ~/.bash_aliasesπΉ But if you are in windows machine add the executibles in your path. If you are using Laragon then it can be
C:\laragon\www\project_name\vendor\bin\;C:\laragon\www\project_name\;πΉ Now you can run elham command through out your project. To check run from the terminal if you are in linux enviornment
elhamπΉ But if you are in windows, then
php elhamπΉ Elham provides you the build:controller command
elham build:controller YourControllerπΉ Check it by finding it in app/Controller directory of your project.
πΉ By default elham generates resourceful controller. But if you want you can always make a plain controller by running
elham build:controller YourController plainπΉ Elham also provides you build:model command
elham build:model YourModelπΉ It'll create a model with necessary properties & methods based on your database table.
πΉ Elham ships with build:form command
elham build:form YourFormπΉ A dummy blade form will be generated inside app/Views/_partials directory.
πΉ Elham also provides you build:validator command
elham build:validator YourValidatorπΉ A validation class will be generated inside app/Validation directory.
πΉ Now if you need any help just type
elham help build:keywordπΉ All the commands check the existing ones as well for simplicity.
πΉ Elham ships with Blade and Plain view for rendering its View. But if you want you can use twig too. For that you will need to install TWIG by the following command
composer require twig/twigπΉ As Elham used Phinx for migrations & seeding, so to use phinx command just run from the terminal
echo "alias phinx='./phinx'" >> ~/.bash_aliases && source ~/.bash_aliasesπΉ Now you'll be able to run phinx command. To make sure phinx running correctly, run in terminal
phinxπΉ You'll get the list of Phinx command. To use phinx, first initialize it by the following command
phinx initπΉ A phinx.yml file will be generated. You need to customize it. Sample customization for development listed below
environments:
default_database: development
development:
adapter: sqlite
host: localhost
name: db/database.sqlite
user: root
pass: ''
port: 3306
charset: utf8πΉ Phinx uses π« CamelCase for its functioning & it'll store the migrations & seeding inside db/migration & db/seeds directory respectively. So if you wanna create a migration for Students table, just run in terminal
phinx create StudentsπΉ A new unique migration for Students will be generated inside db/migrations directory of Elham like below
use Phinx\Migration\AbstractMigration;
class Students extends AbstractMigration
{
public function change()
{
}
}πΉ Now we not gonna use the change method for the migration. Beside we'll create two methods up() & down() for our migration & rollback. So for that we gonna code a bit something like below. Say we've our student table consisting with roll & name.
use Phinx\Migration\AbstractMigration;
class Students extends AbstractMigration
{
public function up()
{
$students = $this->table('students');
$students->addColumn('name','string',['length'=>100])
->addColumn('roll','string')
->create();
}
public function down()
{
$this->dropTable('students');
}
}πΉ Now to migrate, run from terminal
phinx migrateπΉ It'll affect our default db/databse.sqlite hopefully. Now to rollback, just run from terminal
phinx rollbackπΉ To explore more about Phinx, please read the πdocumentation.
πΉ Now for seeding, we just need to create the seeder class from the cli. Say, we need to create a UserSeeder to seed some datumn into users table. To create the UserSeeder class
phinx seed:create UserSeederπΉ We'll get the UserSeeder class inside db/seeds directory. Inside there, we'll get
<?php
use Phinx\Seed\AbstractSeed;
class UserSeeder extends AbstractSeed
{
public function run()
{
}
}πΉ Actually we can seed in βοΈ ways.
1οΈβ£ Manual Seeding
2οΈβ£ Faker Seeding
πΉ For Manual Seeding we can write something like this in UserSeeder class
<?php
use Phinx\Seed\AbstractSeed;
class UserSeeder extends AbstractSeed
{
public function run()
{
$data = array(
array(
'username' => 'chandan07cse',
'password' => md5('me'),
'email' => 'freak.arian@gmail.com',
'image' => 'public/images/chandan07cse.jpg',
'activation_code' => md5(rand(0,1000)),
'active' => 1
),
array(
'username' => 'mamun10pgd',
'password' => md5('mamun10pgd@!'),
'email' => 'rajmamunet@gmail.com',
'image' => 'public/images/mamun10pgd.jpg',
'activation_code' => md5(rand(0,1000)),
'active' => 0
)
);
$this->insert('users', $data);
}
}πΉ Now run from terminal
phinx seed:runπΉ If you wanna run a specific class then run
phinx seed:run -s UserSeederπΉ For faker seeding, we can write something like this in UserSeeder class
<?php
use Phinx\Seed\AbstractSeed;
class UserSeeder extends AbstractSeed
{
public function run()
{
$faker = Faker\Factory::create();
$data = [];
for ($i = 0; $i < 4; $i++) {
$data[] = [
'username' => $faker->userName,
'password' => md5($faker->password),
'email' => $faker->email,
'image' => $faker->image($dir = 'public/images',$width = 640, $height = 480),
'activation_code'=> $faker->randomElement(),
'active' => $faker->boolean
];
}
$this->insert('users', $data);
}
}πΉ Elham also uses Psyshell for tinkering with its functionalities, so to use psysh command just run from the terminal
echo "alias psysh='./psysh'" >> ~/.bash_aliases && source ~/.bash_aliasesπΉ Now if you wanna tinkering with psyshell just run in terminal
psyshπΉ You'll be into the Psyshell now. If you wanna start toying around then first initialize the proper environment. To init the environment, run in terminal
$environment = new Dotenv\Dotenv(__DIR__);
$environment->load();πΉ To init the database with eloquent, run in terminal
$db = new config\Database;πΉ Now if you wanna query through Eloquent/Query Builder, create an instance of the Capsule
$db->eloquent();πΉ Now if you wanna play with User model, create an object of User by running in terminal
$user = new Elham\Model\User;πΉ To get all data from User model, just run in terminal
$user->all()->toArray();πΉ And if you wanna query through PDO, create an instance of the PDO
$pdo = $db->pdo();πΉ If you wanna insert some data into users table using pdo, do the following
$pdo = $pdo->prepare("insert into users values(:id,:username,:email,:password,:image,:activation_code,:active)");
$pdo->execute([':id'=>null,':username'=>'moin07cse',':password'=>'hjkkjhkjjk',':image'=>'moin.png',':activation_code'=>'dfsf',':active'=>0]);
$pdo->fetchAll(PDO::FETCH_ASSOC);πΉ You can run every bit of eloquent & pdo queries along with other functionalities through Psyshell.
πΉ Elham uses Unirest libraries for its api calling. Its pretty easy to call an api using the Elham's api method like below
$uri = 'http://mockbin.com/request';
$content_type = 'application/json';
$request_parameter = ['foo' => 'hello', 'bar' => 'world'];
$request_type = 'post';
$api_response = $this->api($uri,$content_type,$request_parameter,$request_type);πΉ To check any vulnerable package issue in Elham, just run the following command
elham check:vulnerabilityπΉ Elham uses Gulp for basic front-end housekeeping of tasks like minifying css,js, autoprefixing of css and so on & so forth. To use gulp, first install node js by the following command
sudo apt-get install npmπΉ After that we need to install gulp globaly by the following command in ubuntu.
sudo npm install -g gulpπΉ But if you are in windows then in Laragon terminal type
npm install -g gulpπΉ As pacakge.json already ships with Elham. So you don't have to create it. To install gulp just run the following command
sudo npm install gulp --save-devπΉ But if you are in windows, then run
npm install gulp --save-devπΉ The way Gulp work is - Everything is split into various plugins. So each plugin does one job & one job only. And that way we can pipe the output of one function to another. So we can say - Let's autoprefix this file & then minify it & then output it some file & then finally provide some sort of notifications. All of that stuff is really easy with Gulp.
πΉ So if we want to use plugins, we need to install some. Lets install, just to get started, How about minifying our css We can do that by running into ubuntu terminal
sudo npm install gulp-clean-css --save-devπΉ For windows run
npm install gulp-clean-css --save-devπΉ Now if you wanna minifying the js then in ubuntu terminal
sudo npm install gulp-jsmin --save-devπΉ But if you are in windows then run in Laragon terminal
npm install gulp-jsmin --save-devπΉ To use gulp, run from terminal
gulpπΉ Elham proudly compatibles with ngrok. So you can deploy it less than a second. For that you'll have to install node & nodejs-legacy by the following command
sudo apt-get install node
sudo apt install nodejs-legacyπΉ After that we gonna install ngrok through (npm)node package manager globally
sudo npm install ngrok -gπΉ Now we gonna deploy our project by just running the following command
ngrok http 8000πΉ Make sure you are running your project through port 8000. If you are using other port, then use that port to ngrok
πΉ Don't worry it also supports any repo(Github,Gitlab,Bitbucket....) and any CI (Jenkins) and any server(Linux Distro. preferred) in deployment.