I’ve been learning Laravel the last few days and today wanted to experiment both with finding and installing a package/bundle (what’s the term?) and user account management.
2 birds. 1 stone. Confide.
It’s never as easy as they say, but it also wasn’t overwhelming.
First off, I put my php version in my path so everything would use the MAMP php:
export PATH=/Applications/MAMP/bin/php/php5.5.3/bin:$PATH
With Composer and Laravel installed, here are the steps I took to install and configure Confide…
NOTE: A couple things didn’t go 100% smoothly and I went back and redid them. So if my steps are a bit off, please let me know.
file = edits for the file specified
cmd = command line command
1. Create a new Laravel app
cmd: cd /Applications/MAMP/htdocs
cmd: laravel new login
cmd: cd login
cmd: php artisan key:generate
2. Add Confide to the app
file: composer.json
Append to the require section:
“zizaco/confide”: “3.1.x”
cmd: composer update
3. Configure App Provider and Alias
file: app/config/app.php
Append to the providers section:
‘Zizaco\Confide\ConfideServiceProvider’,
Append to the aliases section:
‘Confide’ => ‘Zizaco\Confide\ConfideFacade’,
4. Configure Auth, Mail and Database
file: app/config/auth.php
(no changes, but the installation instructions had something so…)
file: app/config/mail.php
‘host’ => ‘smtp.<email domain for you>.com’, // where your URL is for your account
(plus username, password, port 587 (default))
‘from’ => array(‘address’ => ‘bear@xyz.com’, ‘name’ => ‘Brainwash Inc.’),
file: app/config/database.php
‘database’ => ‘laravel’,
‘password’ => ‘root’,
(or whatever your local MySQL database setup is)
5. Create Migration
cmd: php artisan confide:migration
cmd: php artisan migrate
6. Edit User to Extend ConfideUser and Declare Validation Rules
file: app/models/User.php
change the declaration to be…
use Zizaco\Confide\ConfideUser; class User extends ConfideUser implements UserInterface, RemindableInterface { /** * Validation rules */ public static $rules = array( 'email' => 'required|email', 'password' => 'required|between:4,11|confirmed', ); ...
7. Create Controller and Routes
cmd: php artisan confide:controller –restful
cmd: php artisan confide:routes –restful
cmd: composer dump-autoload
cmd: php artisan routes
8. Edit Filters for Login Redirect and Admin
file: app/filters.php
Route::filter('auth', function() { if (Auth::guest()) return Redirect::guest('user/login'); }); // Only authenticated users will be able to access routes that begins with // 'admin'. Ex: 'admin/posts', 'admin/categories'. Route::when('admin*', 'auth');
9. Try to Create a User (fail)
UI: http://localhost:8888/login/public/user/create
Creating a user failed!!!
Message: “Call to undefined method Illuminate\Http\Request::hasSessionStore()”
This site: https://github.com/laravelbook/ardent/issues/155 recommends going back to Laravel 4.1.16
10. Revert to Laravel 4.1.16
file: composer.json
“laravel/framework”: “4.1.16”,
cmd: composer update
UI: http://localhost:8888/login/public/user/create
Then it worked. The email confirmation/reset password seems to be questionable as to how reliable it is. I tried it w/ a couple different servers so hopefully I’ll get it reliable.