Date: 2 Feb 2017
Laravel version: 5.1.0
Guide assumes that you have installed Homestead following official guide,
and have the homestead
command alias:
function homestead() {
( cd ~/Homestead && vagrant $* )
}
homestead up
-
Edit
Homestead/Homestead.yaml
-
Add site mapping in the
sites
key, e.g:sites: - map: somesite.dev to: /home/vagrant/Sites/somesite/public # Path is relative to Homestead insternal fs
-
Edit
/etc/hosts
with the host, e.g:# Homestead Hosts 192.168.10.10 somesite.dev
-
Reload the Homestead vagrant env:
homestead reload --provision
First, download the Laravel installer using Composer:
composer global require "laravel/installer"
Make sure to place the $HOME/.composer/vendor/bin
directory (or the equivalent directory for your OS) in your $PATH so the laravel
executable can be located by your system.
Once installed, the laravel new
command will create a fresh Laravel installation in the directory you specify. For instance, laravel new blog
will create a directory named blog
containing a fresh Laravel installation with all of Laravel's dependencies already installed:
laravel new blog
Laravel needs almost no other configuration out of the box. You are free to get started developing! However, you may wish to review the config/app.php
file and its documentation. It contains several options such as timezone
and locale
that you may wish to change according to your application.
You may also want to configure a few additional components of Laravel, such as:
- The
app
directory, as you might expect, contains the core code of your application. We'll explore this folder in more detail soon. - The
bootstrap
folder contains a few files that bootstrap the framework and configure autoloading. - The
config
directory, as the name implies, contains all of your application's configuration files. - The
database
folder contains your database migration and seeds. - The
public
directory contains the front controller and your assets (images, JavaScript, CSS, etc.). - The
resources
directory contains your views, raw assets (LESS, SASS, CoffeeScript), and "language" files. - The
routes
directory contains all of the route definitions for your application. By default, three route files are included with Laravel: web.php, api.php, and console.php - The
storage
directory contains compiled Blade templates, file based sessions, file caches, and other files generated by the framework. - The
tests
directory contains your automated tests. - The
vendor
directory contains your Composer dependencies.
E.g. let's create a Stays model
php artisan make:model Stay --migration
This will create a migration + model:
app/Stay.php
database/migrations/2017_03_03_112850_create_stays_table.php
Now you'll probably want to go to the Migration file and add some fields, e.g:
public function up()
{
Schema::create('stays', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->date('date_start');
$table->date('date_end');
$table->timestamps();
});
}
php artisan make:controller StayController --resource --model=Stay
Note: if you want to create it in the Admin space, you'd do:
php artisan make:controller \Admin\\StayController --resource --model=Stay