Skip to content

Instantly share code, notes, and snippets.

@gkarugi
Forked from hofmannsven/README.md
Created May 22, 2017 09:23
Show Gist options
  • Save gkarugi/8c92e5bb39e1501b4b3f3352726a99be to your computer and use it in GitHub Desktop.
Save gkarugi/8c92e5bb39e1501b4b3f3352726a99be to your computer and use it in GitHub Desktop.
Notes on working with Laravel 5

Working with Laravel 5

Tools

Tutorials

Usage

Show version: php artisan --version

Show all commands: php artisan list

Show all routes: php artisan route:list

Setup

Key: php artisan key:generate

Setup Homestead with Vagrant

Fix authentication failure on bootup

Problem: $ vagrant up results in authentication failure.

default: Warning: Authentication failure. Retrying...

Solution: SSH into the VM via $ ssh vagrant@localhost -p 2222 and remove and regenerate the private keys:

wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
chown -R vagrant:vagrant .ssh

Mcrypt

Install Mcrypt via Homebrew: brew install mcrypt

Setup Permissions

Make sure to grant Apache access to store data within storage:

  • storage/app
  • storage/framework
  • storage/logs

See: https://gist.github.com/hofmannsven/8392477#permissions

Daily logs: Add APP_LOG=daily to your .env config file (see config/app.php).

Setup with AngularJS

Follow: https://scotch.io/quick-tips/quick-tip-using-laravel-blade-with-angularjs

Populate: php artisan db:seed

Populate a specific database: php artisan db:seed --database mysql_testing

Create new migration: php artisan make:migration create_tasks_table --create=tasks » see database/migrations

Migrate: php artisan migrate

Migrate, again: php artisan migrate:refresh

Migrate a specific database: php artisan migrate --database mysql_testing

Model

Create new model: php artisan make:model Task » see app

Create new model and do migration: php artisan make:model Task -m

Policy

Create new policy: php artisan make:policy TaskPolicy » see app/Policies

Create views: php artisan make:auth --views » see resources/views/auth

Create: php artisan make:middleware BeforeMiddleware » see app/Http/Middleware

Note: The name of the event is usally set in past tense (event is already done).

Add new event with listeners in app/Providers/EventServiceProvider.php

Create new events automatically based on your EventServiceProvider: php artisan event:generate » see app/Events and also app/Listeners

Create command: php artisan make:console AppAbout --command=app:about » see app/Console/Commands

Register new command: » see app/Console/Kernel.php

Usage: php artisan app:about

Usage: php artisan make:test UserTest

Configuration

Add testing database credentials to your phpunit.xml file:

<env name="DB_HOST" value="192.168.10.10"/>
<env name="DB_DATABASE" value="homestead"/>
<env name="DB_USERNAME" value="homestead"/>
<env name="DB_PASSWORD" value="secret"/>

Use temporary in memory database:

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

Composer

Re-generate autoload: composer dump-autoload

Cache: php artisan route:cache

Clear: php artisan route:clear

Interacting with the application

Usage: php artisan tinker

E.g. create User: $user = factory(App\User::class)->create();

Working with Laravel/Blade

Comment: {{-- Hello World! --}}

Include: @include('modules.header')

Styles: {{ HTML::style('css/vendor/normalize.css') }}

Scripts: {{ HTML::script('js/vendor/jquery.min.js') }}

<?php
Blade::setContentTags('<%', '%>'); // For variables and all things Blade.
Blade::setEscapedContentTags('<%%', '%%>'); // For escaped data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment