Showing posts with label laravel. Show all posts
Showing posts with label laravel. Show all posts

Sunday, 19 September 2021

request headers in http options (angular)

 https://stackoverflow.com/questions/53980413/angular-common-http-has-no-exported-member-requestoptions

Tuesday, 21 February 2017

Topic (Laravel) 2 - Routing and Configuring Database

Basic Routing 


Previous lesson we have learn installing Laravel Framework via composer in Windows OS. Basically the first thing when you open a localhost website laravel is that you will notice the "route" thing on website URL.Such that  http://localhost/laraveltest/public/  will direct us to welcome page stated in our route.php. Eloquent 5.x changes route.php inside routes directory located at routes\web.php. 

Example of source code that direct welcome page by returning view model named welcome.php.
Route::get('/', function () {
    return view('welcome');
});

Route Parameters

Eventually Laravel Framework provide a future that enables view of specific segment divide according to each object. Such as to distinct or finding exclusive customer we can pass the parameter using 'customer/{id}' .

Route::get('customer/{id}', function ($id) {
    return 'Customer'.$id;
});

Database Configuration


The database of your laravel project is located at config/database.php. By default laravel will use mysql as default database connection and connect to localhost server. 
'default' => env('DB_CONNECTION', 'mysql'),

However you can change specific connection on this file according to your remote host server.

'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

    ],
Diiference between env file & config/database.php

That file (config/database.php) is the actual configuration file that will be used. That file just happens to pull some values from the env. This allows you to not have to change the config files themselves when you have a project on different servers. You can just have a different .env file on each host that specifies its unique values for those.
Imagine you are working with other people. They will have different configuration for their database. Having to hardcode values into the config file that is committed to a repository would end up with some problems as they pull down changes their configs might get overwritten. The .env file is not committed and should not be as its unique to the 'host'.
By having the config files pull values from env, each person (host) can have their own .env file with their own values without having to make changes to the actual config files.


References

https://laravel.com/docs/5.4/routing
https://laravel.io/forum/05-28-2016-env-file-vs-configdatabasephp

Monday, 20 February 2017

Topic (Laravel) 1 - Laravel Framework Installation

Below are steps instruction for someone to get started with Laravel framework hence using it in day-to-day business operation in development environment.

Step 1 - Download composer and install it on your computer. 

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. You can get composer from here.

Step 2 - Install Laravel 

You can install Laravel by issuing the Composer create-project command in your terminal. But before that, you need to make sure the directory of your project must install according to intended directory.

For this example we change directory in cmd to www folder inside wamp server
cd c:\wamp64\www
Then, you can write down :
composer create-project laravel/laravel laraveltest
The composer will create the laravel project folder for you. Installation may require several minutes. 

You may find the created folder in this directory :



cd c:\wamp64\www\laraveltest



Step 3 - Open Laravel using Localhost

After installation is success, you may open front page by typing on website address. 

http://localhost/laraveltest/public/



OR

you can serve up the local host using artisan command  and then open our website using command line http://localhost:8000/ 


php artisan serve

http://localhost:8000/


If after git clone , you may need to do these:

1. composer dump-autoload
2. composer install
3. php artisan key:generate

References

https://laravel.com/docs/5.4
https://www.tutorialspoint.com/laravel/laravel_installation.htm