Example #1
0
 /**
  * Returns the currently logged in User
  *
  * @return \App\Eloquent\User|null
  */
 public function user()
 {
     try {
         //Check if user is logged in
         if (!$this->check()) {
             //Simply return null
             return null;
         }
         //Get CI super object
         $ci =& get_instance();
         //Get user id from session
         $userId = $ci->keeper->get('logged_in_user');
         //Get the user
         //SELECT * FROM users WHERE id = $userId
         $user = User::findOrFail($userId);
         //Return the user
         return $user;
     } catch (Exception $e) {
         //Unknown error or unexpected results
         return null;
     }
 }
 /**
  * Returns the feeds for a user
  *
  * @param \App\Eloquent\User $user
  * @param int $numberPerPage
  * @return \Illuminate\Pagination\LengthAwarePaginator|null
  */
 public function feeds($user = null, $numberPerPage = 3)
 {
     try {
         //Get CI super object
         $ci =& get_instance();
         //Calculate page
         $page = $ci->input->get('page') !== false ? $ci->input->get('page') : 1;
         //Count the posts
         $postsCount = $this->post->with(['user'])->whereHas('user', function ($query) use($user) {
             $query->whereIn('id', $user->friends()->lists('users.id')->merge([$user->id])->all());
         })->count();
         //No posts found
         if ($postsCount == 0) {
             //Return null
             return null;
         }
         //Limiting posts
         $limitsPosts = $this->post->with(['user'])->whereHas('user', function ($query) use($user) {
             $query->whereIn('id', $user->friends()->lists('users.id')->merge([$user->id])->all());
         })->skip($numberPerPage * ($page - 1))->take($numberPerPage)->orderBy('created_at', 'desc')->get();
         //No posts on this page
         if ($limitsPosts->count() == 0) {
             //Return null
             return null;
         }
         //Return paginator
         return new LengthAwarePaginator($limitsPosts, $postsCount, $numberPerPage, $page, ['path' => current_url()]);
     } catch (Exception $e) {
         //Unexpected error
         return null;
     }
 }
Example #3
0
     return $page;
 });
 $perPage = 5;
 // results per page
 $columns = ['*'];
 // (optional, defaults to *) array of columns to retrieve from database
 $pageName = 'page';
 // (optional, defaults to 'page') query string parameter name for the page number
 if (User::all()->count() <= $perPage) {
     exit("Need more than <strong>{$perPage}</strong> users in your <i>illuminate_non_laravel</i> database to see this work");
 }
 // Set $page (optional, defaults to null) to the current page;
 // if this is not set, the currentPageResolver will be used
 $page = isset($_REQUEST[$pageName]) ? $_REQUEST[$pageName] : null;
 // Query and paginate the results
 $results = User::orderBy('id')->paginate($perPage, $columns, $pageName, $page);
 // Display the table of users
 echo '<h1>Users</h1>';
 echo '<table>';
 foreach ($results as $user) {
     echo "<tr><td>User number {$user->id}</td></tr>";
 }
 echo '<table>' . "\n";
 // Render the Bootstrap framework compatible pagination html;
 // the appends() method retains any other query string parameters
 // so that they can be passed along with pagination links
 echo $results->appends($_GET)->render();
 // additional helper methods available are:
 // $results->count();
 // $results->currentPage();
 // $results->hasMorePages();
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'uid' => rand(), 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
Example #5
0
 * Requires: illuminate/database
 *
 * @source https://github.com/illuminate/database
 */
$app = new \Slim\Slim();
$app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
$app->get('/', function () {
    $capsule = new Capsule();
    $capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'illuminate_non_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
    // Set the event dispatcher used by Eloquent models... (optional)
    $capsule->setEventDispatcher(new Dispatcher(new Container()));
    // Set the cache manager instance used by connections... (optional)
    // $capsule->setCacheManager(...);
    // Make this Capsule instance available globally via static methods... (optional)
    $capsule->setAsGlobal();
    // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
    $capsule->bootEloquent();
    // Use it
    echo '<pre>';
    $user = Capsule::table('users')->where('id', 1)->get();
    var_dump($user);
    $users = User::all();
    var_dump($users);
    // More examples and docs here: https://github.com/illuminate/database
});
$app->get('/encapsulated', function () {
    echo '<pre>';
    $users = UserEncapsulated::all();
    var_dump($users);
});
$app->run();
 /**
  * Seed invitations for a user
  *
  * @param string $userId
  */
 public function seedInvitations($userId = '')
 {
     //Unguard model
     Model::unguard();
     $numRequestToSend = mt_rand(10, 100);
     //Get the user
     $user = \App\Eloquent\User::findOrFail($userId);
     //Get number of users accordingly
     $users = \App\Eloquent\User::where('id', '!=', $userId)->orderByRaw('RAND()')->limit($numRequestToSend)->get();
     //Seed friend request
     foreach ($users as $someUser) {
         //Create friend request for user
         $user->receivedFriendRequests()->create(['sender' => $someUser->id, 'notified' => false]);
     }
     echo $numRequestToSend . ' requests created';
     Model::reguard();
 }
 /**
  * Change the user password
  *
  * @param \App\Eloquent\User $user
  * @param string $password
  * @return bool
  */
 public function updatePassword($user, $password)
 {
     //Update password
     $user->password = $password;
     //Save user data
     return $user->save();
 }