Skip to content

Instantly share code, notes, and snippets.

View naneri's full-sized avatar
👔

Kana naneri

👔
View GitHub Profile
@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 / 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 / disable_global.sql
Last active January 27, 2016 08:30
Disable foreign key checks
SET GLOBAL FOREIGN_KEY_CHECKS=0;
<?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'],
<?php
// Composer: "fzaninotto/faker": "v1.3.0"
use Faker\Factory as Faker;
class TeamsTableSeeder extends Seeder {
public function run()
{
DB::table('teams')->delete();
<?php
use Faker\Factory as Faker;
class TeamsTableSeeder extends Seeder {
public function run()
{
DB::table('teams')->delete();
$faker = Faker::create();
<?php
class CompaniesTableSeeder extends Seeder {
public function run()
{
DB::table('companies')->delete();
$faker = Faker\Factory::create();
<?php
class CompaniesTableSeeder extends Seeder {
public function run()
{
DB::table('companies')->delete();
$faker = Faker\Factory::create();
<?php
class UsersTableSeeder extends Seeder{
public function run(){
DB::table('users')->delete();
$faker = Faker\Factory::create();
for ($i = 0; $i < 100; $i++)
<?php
// app/filters.php
App::before(function($request)
{
// Set default locale.
$mLocale = Config::get( 'app.locale' );
// Has a session locale already been set?
if ( !Session::has( 'locale' ) )
{