Laravel:

    Start your Laravel webapp

    Introduction

    This guide is going to help you start developing your Laravel applications at SourceLair and make the most out of SourceLair's capabilities.

    This guide assumes that you already have a SourceLair account.

    Setup

    Laravel is a PHP framework so first of all you need to create a new PHP project. When you create a PHP project, SourceLair launches an Apache web server to serve applications from the root directory of the project. In order to start coding your Laravel app you need to install Laravel and configure your server in SourceLair.

    Delete default files

    Laravel starts with its own skeleton, so it's better to delete the default files that come with the PHP project type in SourceLair. To delete everything except .git directory run the following command in your terminal:

    $ rm -r !(.git) 2>/dev/null
    

    Install a Laravel application

    Composer is pre-installed into your server and so you can use its commands from your fully featured terminal.

    The composer create-project command is one of the ways you can bootstrap a new project based on the laravel/laravel standard application skeleton. The command below sets it up in a directory named my_laravel using the latest version of the framework.

    $ composer create-project laravel/laravel --prefer-dist my_laravel
    

    After downloading ​all the required dependencies and running a few hooks, Composer will ​have​ set up a fully functional project in the directory you specified (my_laravel in our case).​ Since the Git repository is already initialized in the root directory, we'll have to move the contents of the new Laravel project one level up with the following command:

    $ shopt -s dotglob && mv my_laravel/* . && shopt -u dotglob
    

    and remove the existing folder:

    $ rmdir my_laravel
    

    Configure server command

    By default, your Apache server runs the apache2ctl -DFOREGROUND command serving the content of the root directory (/mnt/project) of your project. In laravel's basic skeleton, application's document root is the /public subdirectory so you need to create a Procfile.dev that configures the correct document root:

    $ echo "web: ln -s /mnt/project/public /var/www/app && apache2ctl -DFOREGROUND" > Procfile.dev
    

    After creating the Procfile.dev you need to restart your server - using the Server: Restart server Command Palette command - so that your server will run following the Procfile.dev file .

    Preview your application

    SourceLair provides you with a Public URL in order to help you test and showcase your work. There are 2 ways to see the public URL of your project:

    • Click on the eye icon in the sidebar
    • Open the Command Palette (Ctrl/Cmd + Shift + P) and use the Server: Open Public URL command.

    Deployment

    The recommended way to deploy your application to production is via Heroku. SourceLair's integration with Heroku toolbelt makes things pretty simple as you can deploy your app without even leaving from SourceLair.

    Before you start setting up our deployment workflow, check out that you have:

    Create a Procfile

    At the setup step you have already created a Procfile.dev file to customise your server commands during development. Now you need to create a Procfile file that will give the appropriate instructions to Heroku about our server commands in production.

    $ echo web: vendor/bin/heroku-php-apache2 public/ > Procfile
    

    After creating the Procfile don't forget to commit this new file.

    Set up Heroku workflow

    SourceLair terminal is integrated with Heroku toolbelt thus you are able to use all Heroku commands via SourceLair. Initially, you need to login to Heroku filling in your Heroku credentials

    $ heroku login
    

    Then, you need to create a new Heroku application that you can push to.

    $ heroku create
    

    Heroku supports a variety of languages, and attempts to detect which one your code is written in when you deploy. This happens in a particular order, and because the Laravel code also contains a package.json file, Heroku will assume your application is written in Node.js unless you explicitly declare it as a PHP application:

    $ heroku buildpacks:set heroku/php
    

    Laravel uses an application encryption key to encrypt user sessions and other information. Its value will be read from the APP_KEY environment variable. The easiest way to generate a valid key is using the php artisan key:generate --show command and adding the printed key to the heroku config:set command, so in one command:

    $ heroku config:set APP_KEY=$(php artisan --no-ansi key:generate --show)
    

    Deploy

    Everything should be set up, so you need deploy your app from SourceLair to Heroku. To do so use the Command Palette command Heroku: Deploy.

    Now every time you want to push something new to production, all you have to do is commit your changes and deploy to Heroku.

    Extras - Tips to code faster

    SourceLair provides you with some great features in order to help you develop faster your website being focused on the creative part of programming.

    Auto-format

    When you write your PHP, HTML or CSS files, SourceLair's editor automatically place your cursor at the correct indentation level so that you don't have to worry about it. Although, when you break down your format you can select the number of lines you want to "auto-format" and press Shift + Tab.

    Command Palette

    Command Palette is a free text search tool which helps you use most of SourceLair's features really fast. You can open it by pressing Ctrl/Cmd + Shift + P.

    Quickopen

    Quickopen is a fast and time saving way to navigate through your filesystem in order to find and open any file you want using your keyboard.

    You can open the Quickopen prompt using its shortcut Ctrl/Cmd + Shift + O.

    Find in files

    Find in files is a simple and easy way to search for something in your entire project at once, with quick file navigation from the results.

    You can trigger the Find in files prompt using its shortcut Ctrl/Cmd + Shift + F.