Skip to content

Instantly share code, notes, and snippets.

View naneri's full-sized avatar
👔

Kana naneri

👔
View GitHub Profile
<?php
class CompaniesTableSeeder extends Seeder {
public function run()
{
DB::table('companies')->delete();
$faker = Faker\Factory::create();
<?php
use Faker\Factory as Faker;
class TeamsTableSeeder extends Seeder {
public function run()
{
DB::table('teams')->delete();
$faker = Faker::create();
<?php
// Composer: "fzaninotto/faker": "v1.3.0"
use Faker\Factory as Faker;
class TeamsTableSeeder extends Seeder {
public function run()
{
DB::table('teams')->delete();
<?php
public function postDatabase()
{
$data = Input::all();
$newDbConfig = new NewConfig;
$newDbConfig->toFile(app_path().'/config/database.php', [
'connections.mysql.host' =>$data['host'],
'connections.mysql.database' =>$data['database'],
'connections.mysql.username' =>$data['username'],
@naneri
naneri / disable_global.sql
Last active January 27, 2016 08:30
Disable foreign key checks
SET GLOBAL FOREIGN_KEY_CHECKS=0;
@naneri
naneri / tricks.md
Created February 23, 2016 07:43
Laravel tricks

Adding seed data to migrations.

It often happens that you need some data to be available inside a migration. But the same data might be required in a Seeder (if you want to run it on test environtment). To make the data available for both in Seeder and Migration - you can simply call it inside a migration. Like that:

$seeder = new YourClassSeeder();
$seeder->run();

But you have to check inside the seeder file if the data is already available for your App, (so that you would not end up with two sets of the same data, after calling both migrations and seeders in testing machine).

@naneri
naneri / drop.php
Created July 17, 2016 19:02
Drop all tables in Laravel
<?php
foreach(\DB::select('SHOW TABLES') as $table) {
$table_array = get_object_vars($table);
\Schema::drop($table_array[key($table_array)]);
}
@naneri
naneri / add_identity.sh
Last active July 29, 2016 11:31
Adds ssh identity to a server
cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
@naneri
naneri / select.blade.php
Created October 4, 2016 08:50
Laravel select
<select name="metrics_reminder" class="form-control list-group-item" required>
<option value="never" @if(old('course_reminder', $user->metrics_reminder) == 'never') selected @endif>Never</option>
@foreach(config('anya.metrics_reminder_intervals') as $value)
<option value="{{$value}}" @if(old('course_reminder', $user->metrics_reminder) == $value) selected @endif>
Once in {{$value}} days
</option>
@endforeach
</select>
@naneri
naneri / query.sql
Created May 20, 2017 10:01
$fLat is the searchers latitude and $fLon the searchers longitude.
SELECT
`id`,
`name`
FROM
`stations`
WHERE
ACOS( SIN( RADIANS( `latitude` ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( `latitude` ) )
* COS( RADIANS( $fLat )) * COS( RADIANS( `longitude` ) - RADIANS( $fLon )) ) * 6380 < 10
ORDER BY
`distance`