Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Eloquent Minus Laravel

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Eloquent Minus Laravel

Avatar for David Hemphill

David Hemphill

April 08, 2014

More Decks by David Hemphill

Other Decks in Technology

Transcript

  1. Hi My name is David, ! I am a designer,

    developer, and all-around good guy. ! @davidhemphill
  2. 1. Existing codebase is not on Laravel ! 2. It’s

    a small project that doesn’t need the power ! 3. Get a taste of Laravel without the commitment
  3. <?php use Illuminate\Database\Capsule\Manager as Capsule; ! $capsule = new Capsule;

    ! $capsule->addConnection([ 'driver' => 'mysql', 'host' => $database['DB_SERVER'], 'database' => $database['DB_DATABASE'], 'username' => $database['DB_USERNAME'], 'password' => $database['DB_PASSWORD'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci' ]); ! $capsule->bootEloquent();
  4. Live Stream • Email-based logins (no user account) • Basic

    PHP Session handling • Needed to interface with an existing database table • Wanted a way to pull out users without a bunch of fuss. (I also wanted to use Eloquent outside of Laravel)
  5. <?php namespace Circles; ! use Illuminate\Database\Eloquent\Model as Eloquent; use Circles\Session;

    ! class User extends Eloquent { protected $table = 'registrations'; protected $timestamps = false; ! public function isLoggedIn() { if ($session_logged_in = $_SESSION['session_logged_in']) { $session_id = $_SESSION['session_id']; $session_email = $_SESSION['session_email']; ! // Get the user with this email $user = User::whereEmail($session_email)->first(); ! return Session::whereUserId($user->id)->first(); } return false; } ! public function hasSession() { return $session = User::whereEmail($this->email) ->where('last_activity', '<', new DateTime) ->first(); } }
  6. "autoload": { "classmap": [ "./lib", "./models" ], "files": [ "./helpers.php",

    "./config/database.php", "./config/config.php", "./start.php" ] }