Laravel
Installation
Download composer and create an alias so that `composer` launches composer:
wget -O - https://getcomposer.org/installer | php -- --install-dir=$HOME/tmp/ alias composer='php $HOME/tmp/composer.phar'
Set up the laravel project using composer:
composer create-project laravel/laravel projectname --prefer-dist
There are many useful commands that comes with laravel's artisan command line PHP script located in the root of the project directory. You may want to create an alias for artisan:
alias artisan='php artisan'
The initial laravel project will come with scaffolding project files which you may want to remove by running:
artisan fresh
Ensure that the webserver serving the laravel application has permission to write to the directories inside the `storagae` directory. If these directories are not writable by the webserver, no error messages will be displayed or logged.
Troubleshooting
You can see what packages and dependencies were installed by running:
composer show -i
All HTTP routes can be listed using `artisan`:
artisan route:list
Database
Migration
Migration is a way to define database schemas and schema changes using PHP. When used with a version control system, it is trivial to replicate, update, or revert database schemas on your local system.
When creating models using `artisan`, `artisan` will automatically create a migration for the table referenced by the new model. After defining the schema in the migration file, you can apply the schema by executing:
artisan migrate
You can reset (drop + re-migrate) using:
artisan migrate:reset
Database Seeding
The `DatabaseSeeder.php` file defines how the database is to be seeded, say after an initial migration. It is possible to import data from an existing database to your development database by executing raw SQL queries like so:
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call('WordsTableSeeder');
}
}
class WordsTableSeeder extends Seeder {
public function run() {
DB::table('words')->delete();
DB::select(DB::raw("INSERT INTO chinese_laravel.words
(word, pronunciation, frequency)
SELECT word, pronunciation, frequency FROM chinese.word"));
}
}
Application
Most of your project files will end up inside the `app` and `resources` directory.
Configuration
Configurations are defined inside the `.env` file located in the root directory of your laravel project. Variables defined in this file override any that are defined in the application configuration files and is the recommended way of setting values.
Routing
All HTTP requests will go through to your `app/Http/` portion of your laravel project.
Models
Models are placed directly in the `app` directory and under the `App` namespace. When working with Models, reference them directly by their namespace or pull in the namespace.
Views
Forms
To use the Illuminate HTML package, pull in the `illuminate/html` dependency using Composer.
composer require illuminate/html
Add the service provider to your config/app.php provider list and create a new facade.
'Form' => 'Illuminate\Html\FormFacade', 'Html' => 'Illuminate\Html\HtmlFacade',
In the blade templates, you can now use:
{!! Form::open() !!}}
{!! Form::label('name', 'Name:') !!}}
{!! Form::text('name', 'default', ['class' => 'blah'] ) !!}}
{!! Form::close() !!}}