private function setUserModel()
 {
     $config = $this->app->make('config');
     $model = $config->get('auth.providers.users.model', function () use($config) {
         return $config->get('auth.model', $config->get('messenger.user_model'));
     });
     Models::setUserModel($model);
     Models::setTables(['users' => (new $model())->getTable()]);
 }
Esempio n. 2
0
 /**
  * Returns all threads with new messages.
  *
  * @return array
  */
 public function threadsWithNewMessages()
 {
     $threadsWithNewMessages = [];
     $participants = Models::participant()->where('user_id', $this->id)->lists('last_read', 'thread_id');
     /**
      * @todo: see if we can fix this more in the future.
      * Illuminate\Foundation is not available through composer, only in laravel/framework which
      * I don't want to include as a dependency for this package...it's overkill. So let's
      * exclude this check in the testing environment.
      */
     if (getenv('APP_ENV') == 'testing' || !str_contains(\Illuminate\Foundation\Application::VERSION, '5.0')) {
         $participants = $participants->all();
     }
     if ($participants) {
         $threads = Models::thread()->whereIn('id', array_keys($participants))->get();
         foreach ($threads as $thread) {
             if ($thread->updated_at > $participants[$thread->id]) {
                 $threadsWithNewMessages[] = $thread->id;
             }
         }
     }
     return $threadsWithNewMessages;
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop(Models::table('participants'));
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop(Models::table('messages'));
 }
Esempio n. 5
0
 /**
  * Participants relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\HasMany
  */
 public function participants()
 {
     return $this->hasMany(Models::classname(Participant::class), 'thread_id', 'thread_id');
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     DB::statement('ALTER TABLE `' . DB::getTablePrefix() . Models::table('participants') . '` CHANGE COLUMN `last_read` `last_read` timestamp NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP;');
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop(Models::table('threads'));
 }
 /**
  * User relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  */
 public function user()
 {
     return $this->belongsTo(Models::classname(User::class), 'user_id');
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     DB::statement('ALTER TABLE `' . DB::getTablePrefix() . Models::table('participants') . '` CHANGE COLUMN `last_read` `last_read` timestamp NULL DEFAULT NULL;');
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::table(Models::table('threads'), function (Blueprint $table) {
         $table->dropSoftDeletes();
     });
 }
Esempio n. 11
0
 /**
  * Generates a select string used in participantsString().
  *
  * @param $columns
  *
  * @return string
  */
 protected function createSelectString($columns)
 {
     $dbDriver = $this->getConnection()->getDriverName();
     $tablePrefix = $this->getConnection()->getTablePrefix();
     $usersTable = Models::table('users');
     switch ($dbDriver) {
         case 'pgsql':
         case 'sqlite':
             $columnString = implode(" || ' ' || " . $tablePrefix . $usersTable . '.', $columns);
             $selectString = '(' . $tablePrefix . $usersTable . '.' . $columnString . ') as name';
             break;
         case 'sqlsrv':
             $columnString = implode(" + ' ' + " . $tablePrefix . $usersTable . '.', $columns);
             $selectString = '(' . $tablePrefix . $usersTable . '.' . $columnString . ') as name';
             break;
         default:
             $columnString = implode(", ' ', " . $tablePrefix . $usersTable . '.', $columns);
             $selectString = 'concat(' . $tablePrefix . $usersTable . '.' . $columnString . ') as name';
     }
     return $selectString;
 }