Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Learning and Work
managing-money-api
Commits
b951f44f
Commit
b951f44f
authored
Aug 20, 2018
by
Jack Stupple
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make currency source from language
parent
9a0a2fcc
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
85 deletions
+44
-85
app/Http/Controllers/Api/LanguageController.php
app/Http/Controllers/Api/LanguageController.php
+1
-1
app/Language.php
app/Language.php
+6
-1
app/Player.php
app/Player.php
+3
-3
database/migrations/2018_04_18_00000_initial.php
database/migrations/2018_04_18_00000_initial.php
+34
-7
database/migrations/2018_04_18_00001_create_currencies_table.php
...e/migrations/2018_04_18_00001_create_currencies_table.php
+0
-38
database/migrations/2018_04_18_00004_add_currency_support_to_players.php
...ions/2018_04_18_00004_add_currency_support_to_players.php
+0
-35
No files found.
app/Http/Controllers/Api/LanguageController.php
View file @
b951f44f
...
...
@@ -6,7 +6,7 @@ class LanguageController extends Controller
{
public
function
index
()
{
// raw because <= NOW() is mysql directly into the function and the builder will misunderstand it otherwise
return
\
App\Language
::
whereRaw
(
'enabled <= NOW()'
)
->
where
(
'enabled'
,
'!='
,
NULL
)
->
get
();
return
\
App\Language
::
whereRaw
(
'enabled <= NOW()'
)
->
where
(
'enabled'
,
'!='
,
NULL
)
->
with
(
'currency'
)
->
get
();
}
public
function
default
()
{
...
...
app/Language.php
View file @
b951f44f
...
...
@@ -6,10 +6,15 @@ use Illuminate\Database\Eloquent\Model;
class
Language
extends
Model
{
protected
$fillable
=
[
'slug'
,
'name'
,
'enabled'
];
protected
$fillable
=
[
'slug'
,
'name'
,
'enabled'
,
'currency_id'
];
public
function
players
()
{
return
$this
->
hasMany
(
Player
::
class
);
}
public
function
currency
()
{
return
$this
->
belongsTo
(
Currency
::
class
);
}
}
\ No newline at end of file
app/Player.php
View file @
b951f44f
...
...
@@ -19,11 +19,11 @@ class Player extends Model
'score'
=>
'float'
];
protected
$appends
=
[
'progress'
,
'questions'
,
'score'
,
'score_string'
,
'season_roundup_position'
];
protected
$appends
=
[
'progress'
,
'questions'
,
'score'
,
'score_string'
,
'season_roundup_position'
,
'currency'
];
public
function
c
urrency
()
public
function
getC
urrency
Attribute
()
{
return
$this
->
belongsTo
(
'App\C
urrency
'
)
;
return
$this
->
language
->
c
urrency
;
}
public
function
language
()
...
...
database/migrations/2018_04_18_00000_initial.php
View file @
b951f44f
<?php
use
App\Currency
;
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
...
...
@@ -170,6 +171,7 @@ class Initial extends Migration
'languages'
,
function
(
Blueprint
$blueprint
)
{
$blueprint
->
increments
(
'id'
);
$blueprint
->
integer
(
'currency_id'
);
$blueprint
->
string
(
'name'
);
$blueprint
->
string
(
'slug'
);
$blueprint
->
timestamp
(
'enabled'
)
->
nullable
();
...
...
@@ -342,9 +344,29 @@ class Initial extends Migration
protected
function
addSupportedLanguages
()
{
Schema
::
create
(
'currencies'
,
function
(
Blueprint
$table
)
{
$table
->
increments
(
'id'
);
$table
->
string
(
'currency_code'
);
$table
->
timestamps
();
});
// default currency
$eur
=
new
Currency
();
$eur
->
currency_code
=
'EUR'
;
$eur
->
save
();
$nok
=
new
Currency
();
$nok
->
currency_code
=
'NOK'
;
$nok
->
save
();
$gbp
=
new
Currency
();
$gbp
->
currency_code
=
'GBP'
;
$gbp
->
save
();
$en
=
\
App\Language
::
firstOrCreate
([
'name'
=>
'English'
,
'slug'
=>
'en'
'slug'
=>
'en'
,
'currency_id'
=>
$gbp
->
id
]);
$en
->
enabled
=
$this
->
created_at
;
...
...
@@ -352,7 +374,8 @@ class Initial extends Migration
$nl
=
\
App\Language
::
firstOrCreate
([
'name'
=>
'Dutch'
,
'slug'
=>
'nl'
'slug'
=>
'nl'
,
'currency_id'
=>
$eur
->
id
]);
$nl
->
enabled
=
$this
->
created_at
;
...
...
@@ -360,23 +383,26 @@ class Initial extends Migration
$de
=
\
App\Language
::
firstOrCreate
([
'name'
=>
'German'
,
'slug'
=>
'de'
'slug'
=>
'de'
,
'currency_id'
=>
$eur
->
id
]);
//
$de->enabled = $this->created_at;
$de
->
enabled
=
$this
->
created_at
;
$de
->
save
();
$no
=
\
App\Language
::
firstOrCreate
([
'name'
=>
'Norwegian'
,
'slug'
=>
'no'
'slug'
=>
'no'
,
'currency_id'
=>
$nok
->
id
]);
//
$no->enabled = $this->created_at;
$no
->
enabled
=
$this
->
created_at
;
$no
->
save
();
$sl
=
\
App\Language
::
firstOrCreate
([
'name'
=>
'Slovenian'
,
'slug'
=>
'sl'
'slug'
=>
'sl'
,
'currency_id'
=>
$eur
->
id
]);
$sl
->
enabled
=
$this
->
created_at
;
...
...
@@ -428,5 +454,6 @@ class Initial extends Migration
Schema
::
dropIfExists
(
'answer_resource_category'
);
Schema
::
dropIfExists
(
'resource_resource_category'
);
Schema
::
dropIfExists
(
'question_categories'
);
Schema
::
dropIfExists
(
'currencies'
);
}
}
database/migrations/2018_04_18_00001_create_currencies_table.php
deleted
100644 → 0
View file @
9a0a2fcc
<?php
use
App\Currency
;
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
CreateCurrenciesTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'currencies'
,
function
(
Blueprint
$table
)
{
$table
->
increments
(
'id'
);
$table
->
string
(
'currency_code'
);
$table
->
timestamps
();
});
// default currency
$currency
=
new
Currency
();
$currency
->
currency_code
=
'EUR'
;
$currency
->
save
();
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'currencies'
);
}
}
database/migrations/2018_04_18_00004_add_currency_support_to_players.php
deleted
100644 → 0
View file @
9a0a2fcc
<?php
use
App\Currency
;
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
AddCurrencySupportToPlayers
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
$currency
=
Currency
::
where
(
'currency_code'
,
'EUR'
)
->
firstOrFail
();
Schema
::
table
(
'players'
,
function
(
Blueprint
$table
)
use
(
$currency
)
{
$table
->
integer
(
'currency_id'
)
->
after
(
'language_id'
)
->
default
(
$currency
->
id
);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
table
(
'players'
,
function
(
Blueprint
$table
)
{
$table
->
dropColumn
(
'currency_id'
);
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment