Refringe

Experience

9,320

1 Best Reply Awards

  • Member Since 2 Years Ago
  • 111 Lessons Completed
  • 3 Favorites

21st August, 2016

Refringe left a reply on Seeding Multiple Foreign Key Records Using Model Factories • 1 year ago

Is there a way to go one step deeper and create (say 10) of App\Player for each of the two teams that are created per user?

Refringe left a reply on Seeding Multiple Foreign Key Records Using Model Factories • 1 year ago

That's exactly what I was looking for. Thank you!

Refringe started a new conversation Seed, Factories, Foreign Keys, Oh My. • 1 year ago

Alright, so I have a User and Team model factory and I'm using a seeder to populate the database. However, I'm trying to ensure that each user that I add has two teams.

This works, but because I'm repeating a line entirely, it feels... dirty?

factory(App\User::class, 30)->create()->each(function ($user) {
    $user->teams()->save(factory(App\Team::class)->make());
    $user->teams()->save(factory(App\Team::class)->make());
});

Is there a more efficient way to do this? It's not a huge deal now, but I'm going to be using this same method to add 20+ child records to a parent with other models and I want to be sure I'm doing it right.

13th June, 2016

Refringe left a reply on Laravel CI Testing With GitLab • 1 year ago

@Fuxy22 It checks to see if Docker exists. If it doesn't then the script halts. @bashy pointed to an issue that explains that this method stops working with newer versions of Docker. This should work with the new version:

[[ ! -e /.dockerinit ]] && [[ ! -e  /.dockerenv ]] && exit 0

However, I have yet to test it.

29th April, 2016

Refringe left a reply on Multiple Domains For Languages • 1 year ago

Bump?

28th April, 2016

Refringe left a reply on Multiple Domains For Languages • 1 year ago

Or would you set each of the domains to load their own copy of the code, but connect to the same database? Is there any downside to that, other than having to manage making releases to two directories at the same time? Am I missing something?

23rd April, 2016

Refringe left a reply on Multiple Domains For Languages • 1 year ago

Using the . env file had crossed my mind but I didn't know how I would load different versions of the file (one per language/domain) while at the same time pointing the domains to the same app folder. Is there a technique for doing that?

Refringe left a reply on Giving Routes Of Different Kinds With Same URL The Same Name? • 1 year ago

If the routes have the same URL there's no point in naming all of them. Just name the GET request and use that route name to generate URLs for all of your other request types with the same route structure. This removes a little bit of unnecessary repetition.

I'm not even sure the delete or post route names would even be picked up in your example because they share the same name. You're not passing the request type to the route function (I don't think you can) so it wouldn't know which one to return. You can test this by simply changing the routes so they're different, but still sharing the same name:

Route::get('show/{id}', 'PostController@show')->name('post');
Route::delete('delete/{id}', 'PostController@delete')->name('post');
Route::post('save/{id}', 'PostController@save')->name('post');

I would expect route('post', $post->id) to return /show/{id}.

If your routes are different URLs then I would recommend giving them a different (descriptive) name per type:

Route::get('view/{id}', 'PostController@show')->name('post.show');
Route::delete('view/delete/{id}', 'PostController@delete')->name('post.delete');
Route::post('view/save/{id}', 'PostController@save')->name('post.save');

22nd April, 2016

Refringe started a new conversation Multiple Domains For Languages • 1 year ago

So let's say I have two domains; hello.com and bonjour.com. I need these two domains share the same codebase. The only difference, other than the domains, are the localization language; one is en and the other fr. What would be the best way to dynamically set the URL and locale in the Laravel settings?

3rd March, 2016

Refringe left a reply on Laravel CI Testing With GitLab • 1 year ago

Alright, I wanted to work with the official PHP docker builds, so here's what I ended up doing. It tests using PHP v5.5, v5.6, and v7 with MySQL v5.6 and v5.7; six tests in total. A test takes about 6-7 minutes on average to compile before running. Thanks for the help!

.gitlab-ci.yml:

before_script:
  - bash .gitlab-ci.sh

variables:
  MYSQL_DATABASE: project_name
  MYSQL_ROOT_PASSWORD: secret

phpunit:php5.5:mysql5.6:
  image: php:5.5
  services:
    - mysql:5.6
  script:
    - php vendor/bin/phpunit --colors

phpunit:php5.6:mysql5.6:
  image: php:5.6
  services:
    - mysql:5.6
  script:
    - php vendor/bin/phpunit --colors

phpunit:php7.0:mysql5.6:
  image: php:7.0
  services:
    - mysql:5.6
  script:
    - php vendor/bin/phpunit --colors

phpunit:php5.5:mysql5.7:
  image: php:5.5
  services:
    - mysql:5.7
  script:
    - php vendor/bin/phpunit --colors

phpunit:php5.6:mysql5.7:
  image: php:5.6
  services:
    - mysql:5.7
  script:
    - php vendor/bin/phpunit --colors

phpunit:php7.0:mysql5.7:
  image: php:7.0
  services:
    - mysql:5.7
  script:
    - php vendor/bin/phpunit --colors

.gitlab-ci.sh:

#!/bin/bash

# Install dependencies only for Docker.
[[ ! -e /.dockerinit ]] && exit 0
set -xe

# Update packages and install composer and PHP dependencies.
apt-get update -yqq
apt-get install git libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq

# Compile PHP, include these extensions.
docker-php-ext-install mbstring mcrypt pdo_mysql curl json intl gd xml zip bz2 opcache

# Install Composer and project dependencies.
curl -sS https://getcomposer.org/installer | php
php composer.phar install

# Copy over testing configuration.
cp .env.testing .env

# Generate an application key. Re-cache.
php artisan key:generate
php artisan config:cache

# Run database migrations.
php artisan migrate

.env.testing:

APP_ENV=testing
APP_DEBUG=true
APP_KEY=key

DB_HOST=mysql
DB_DATABASE=project_name
DB_USERNAME=root
DB_PASSWORD=secret

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
MAIL_DRIVER=log

1st March, 2016

Refringe left a reply on Laravel CI Testing With GitLab • 1 year ago

Hey @noeldiaz, thanks for the reply. Are you sure that's all that's needed for basic unit testing? It's failing for me on the composer install line.

$ composer install --prefer-dist > /dev/null
bash: line 23: composer: command not found

ERROR: Build failed with: exit code 1

Also, will a simple set-up like that get functional testing to work? eg:

$this->visit('/login')->see('Login');

Refringe started a new conversation Laravel CI Testing With GitLab • 1 year ago

I'd love to set Laravel up on GitLab with CI, however I can not find any tutorials on how to configure the .gitlab-ci.yml file for a basic Laravel installation. Does anyone have any experience with this? Currently I'm just on gitlab.com using their shared runners.

21st February, 2016

Refringe left a reply on .env.example And Github Repo • 1 year ago

@xtremer360: Sure, no problem there. But again, why? You're never going to have an absolutely perfect repo where anyone can checkout any commit in your history and expect fully functional code. It's just history, focus on the now. :D

Refringe left a reply on .env.example And Github Repo • 1 year ago

@xtremer360: I'm sure there's a way to do that, but why? Do you expect yourself or others to specifically checkout the commits between when you deleted it and your current commit? Have you tagged commits in that time period? Made releases? If not, there's no reason to rewrite any history. Simply add it back in a new commit and merge it into all of your working branches. Good to go. =)

Refringe left a reply on .env.example And Github Repo • 1 year ago

@xtremer360: So to be clear, you want to go back in your repo's history and rewrite it so a file was never deleted?

Refringe left a reply on .env.example And Github Repo • 1 year ago

Here's how to search for and completely remove sensitive information (like your .env file) from your repo: https://help.github.com/articles/remove-sensitive-data/

I've used the BFG Repo-Cleaner that's mentioned at the bottom of the article. It works like magic.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.