Laravel New Project Steps

Here are my steps for creating a new laravel project. I know the docs are excellent but these are the steps specific to my setup, which is probably pretty common. For reference, I use the laravel installer to create new projects and I use Homestead. I already have Homestead set up so it’s just a matter of changing a few things and the inevitable updates, since this is something I don’t do frequently (thus the need for notes).

1. update laravel installer
composer global update "laravel/installer"

2. create the laravel project
laravel new projectname
cd projectname

3. Update Homestead
cd into your Homestead directory and edit the Homestead.yaml file
Add a new entry to the sites section

4. run
vagrant reload --provision

5. Update your hosts file to add projectname
open -a "Sublime Text" /etc/hosts
use .test extension (I’ve had issues with Chrome and .dev or .app extensions not working)

6. Launch the vagrant box
vagrant up

7. SSH into Homestead and cd into the projectname directory
run
composer install

9. Create a .env file in your project root
Copy everything from .env.example into .env

10. Generate the Application Key from Homestead (all php artisan commands have to be run from Homestead on my setup)
php artisan key:generate

11. Navigate to your projectname.test in the browser – you should get the Laravel welcome page

Add a UITableView to an Existing ViewController in Xcode

Quick and dirty checklist for adding a table view to an existing view controller:

  1. Embed existing view controller in a NavigationController
  2. Drag a UITableView object into the view controller in the storyboard
  3. Make the UITableView the same width and height as the view controller and set the constraints to all four sides with no margins
  4. Create an outlet and connection for the tableView in the view controller class
  5. Add UITableViewDataSource and UITableViewDelegate to the class declaration. Your class should look something like this
    import UIKit
     
    class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
     
        @IBOutlet weak var tableView: UITableView!
         
        override func viewDidLoad() {
            super.viewDidLoad()
        }
     
    }
  6. Select the table view, open the connections inspector and connect the table view’s dataSource and delegate methods to the View Controller object.
  7. If you’re not using static cells, open the attributes inspector and set the number of Prototype Cells to 1

Setting Up Delegates in iOS

This is copied from the iOS Apprentice tutorial on raywenderlich.com but I wanted to put it where I could easily access it. These are the basic steps for setting up a delegate pattern between two objects, where object A is the delegate for object B, and object B will send messages back to A.

  1. Define a delegate protocol for object B
  2. Give object B an optional delegate variable. This variable should be weak
  3. Make object B send messages to its delegate when something interesting happens, such as the user pressing the Cancel or Done buttons, or when it needs a piece of information. You write delegate?.methodName(self, ...)
  4. Make object A conform to the delegate protocol. It should put the name of the protocol in its class line and implement the methods from the protocol.
  5. Tell object B the object A is now its delegate

 

Create keyboard shortcut to toggle Document Outline in Xcode

In Xcode, open Preferences and go to the “Key Bindings” section. Type “outline” in the search filter box. Select “Show Document Outline” and double-click to the right, in the “Key” column. A text box should appear and you can type in your new shortcut. I used Cmd+9.

Installing the Html and Form Builder package back into Laravel 5

Here’s how to get the Form and Html Builder package back when using Laravel 5.

composer require illuminate/html

Then, in /config/app.php add the following to the providers and aliases arrays:

'providers' => [
	...
 
	'Illuminate\Html\HtmlServiceProvider',
],
 
'aliases' => [
 
	...
 
	'Form'=> 'Illuminate\Html\FormFacade', 
	'HTML'=> 'Illuminate\Html\HtmlFacade',
],

 

Using Laravel 5 Auth Middleware

To restrict pages in your app to authentication status, add the middleware to the controller’s constructor.

To restrict a page to guests only (not signed in):

public function __construct()
{
    $this->middleware('guest');
}

For signed in users:

public function __construct()
{
    $this->middleware('auth');
}

If you want to make exceptions for certain methods, just pass those parameters in as an array for the second argument.

$this->middleware('auth', ['except' => 'show']);