Categories
Laravel

Homestead PostgreSQL

PostgreSQL is running in Homestead by default, but you cannot access it from the host machine (though the docs do mention the 54320 forwarded port?)

Instead SSH into the Vagrant box and run migrations locally.

Putty on Windows. I had to convert the default private_key file to ppk. Use PuttyGen to generate a private key, use it as Auth option from putty and vagrant username.

Categories
Laravel

Render Laravel view in Controller

You may want to grab the output of a Laravel view; for example to store in cache. You can do so with the render method;

[code]
$result = View::make( ‘index’, $data );
Cache::put(‘mykey’, $result->render(), 10);
[/code]

 

Categories
Laravel

Redis Alias Unavailable in Laravel

Short Answer, even with Redis installed the ‘Redis’ Facade alias can conflict.

Try renaming the alias in app/config/app.php and reloading the autoloader.

Via StackOverflow.

Categories
Laravel PHP

Mandrill mail from Laravel

The Laravel docs mention adding guzzlehttp/guzzle ~4.0 to composer.json for use with Mandrill’s API.

At the time of writing GuzzleHTTP 5.2 was current. Unclear why 5.2 is not suitable, but it gave the SSL Error 60  locally.

[code]
"require": {
"laravel/framework": "4.2.*",
"guzzlehttp/guzzle": "~4.0"
}[/code]

Seemed to fix it on Windows 8. PHP 5.6

Categories
Laravel

Laravel Mail Callback Scope

Sending email with Laravel uses a callback closure to set the recipient, subject & other headers. You may need that callback to access variables from the scope of the calling code.
Like this:

[code language=”php”]
$to = ‘CaptainMorgan@example.com’;

Mail::send(‘myEmailView’, [‘data’=>value], function($message) use ($to) {
$message->to($to)->subject(‘Hey, do stuff’);
});
[/code]

Ensure a space after use statement.
Via StackOverflow.

Categories
Laravel PHP

Laravel’s PHAR Installer on Windows

Outdated Information. This was posted February 2014. Laravel seems to have moved away from the pre-packaged laravel.phar installation method. Install docs for Laravel 4.2 here

In addition to cloning from Git and installing via Composer Laravel can now be installed via a PHAR file.

The documentation is currently a little Linux centric.

On Windows download the laravel.phar file, open a command prompt in its location and run:

[code]
php laravel.phar new my-project-name
[/code]

That will create a new directory called my-project-name and install Laravel in there. This is a lot faster than installing via composer.

Categories
Laravel

Laravel 4 Authentication

Laravel 4 Authentication – A comprehensive guide

(bookmark) I’m definitely going to be reading this guide to creating an Authenticated App in Laravel (by Christopher Pitt)

Categories
Laravel

Laravel on Shared Hosting

AntJanus gave the basic approach here. It did work for my Hello World test, not sure if there are potential issues waiting, such as with maintenance or framework updates.

Basically install locally (on Composer so far), zip it all up and upload the framework directory to a private folder above public_html.

The public entry point can be directly in public_html if the site is for the domain root, or in a sub-folder. Edit both public/index.php and laravel/bootstrap/paths.php to be able to find each other.

Paths.php looked a bit like this

[29]  'public' => __DIR__.'/../public_html/laravel',
//laravel is sub-directory
Categories
Laravel

Laravel Installation

The intro docs have you using Composer to pull in all its dependencies, which come to about 100mb. Apparently it should be possible to turn off development bundles, but not sure I’ve done it yet.

This composer.json:

{
	"require": {
		"laravel/framework": "4.0.*"
	},
	"autoload": {
		"classmap": [
			"app/commands",
			"app/controllers",
			"app/models",
			"app/database/migrations",
			"app/database/seeds",
			"app/tests/TestCase.php"
		]
	},
	"scripts": {
		"pre-update-cmd": [
			"php artisan clear-compiled"
		],
		"post-install-cmd": [
			"php artisan optimize"
		],
		"post-update-cmd": [
			"php artisan vendor-cleanup",
			"php artisan optimize"
		]
	},
	"config": {
		"preferred-install": "dist"
	},
	"minimum-stability": "dev"
}

Should cut file size down with the vendor-cleanup, but I’m wondering if the artisan command does nothing on my local system. When did it get into Windows?

Code Bright takes a different approach, pulling from GitHub. Haven’t tried it yet though.