Fix budget model/migration to fit year/month blueprint
MODIFY
app/Budget.php
app/Budget.php
@@ -16,14 +16,9 @@ class Budget extends Model {
public function spendings() {
$user = Auth::user();
- $date = $this->attributes['date'];
-
- $month = date('m', strtotime($date));
- $year = date('Y', strtotime($date));
-
return Spending::where('user_id', $user->id)
- ->whereMonth('date', $month)
- ->whereYear('date', $year)
+ ->where('year', $this->attributes['year'])
+ ->where('month', $this->attributes['month'])
->where('tag_id', $this->attributes['tag_id'])
->get();
}

MODIFY
database/migrations/2017_08_03_175227_create_budgets_table.php
database/migrations/2017_08_03_175227_create_budgets_table.php
@@ -9,8 +9,8 @@ class CreateBudgetsTable extends Migration {
Schema::create('budgets', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
- $table->integer('month');
$table->integer('year');
+ $table->integer('month');
$table->float('amount');
});
}

Fix budget model/migration to fit year/month blueprint