Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DB_PORT=3306
DB_DATABASE=monica
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_PREFIX=''
DB_TEST_DATABASE=monica_test
DB_TEST_USERNAME=homestead
DB_TEST_PASSWORD=secret
Expand Down Expand Up @@ -96,4 +97,4 @@ AWS_KEY=
AWS_SECRET=
AWS_REGION=us-east-1
AWS_BUCKET=
AWS_SERVER=
AWS_SERVER=
4 changes: 1 addition & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
UNRELEASED CHANGES:

<<<<<<< HEAD
* Add pets management
* Activities made with contact now appears in the Journal
* Add ability to rate how a day went in the Journal
=======
* Add validation when changing email address
>>>>>>> master
* Add ability to change account's password in the settings
* Show a user's avatar when searching

Expand Down
10 changes: 10 additions & 0 deletions app/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ public function addresses()
return $this->hasMany('App\Address');
}

/**
* Get the Pets records associated with the contact.
*
* @return HasMany
*/
public function pets()
{
return $this->hasMany('App\Pet');
}

/**
* Get the contact records associated with the account.
*
Expand Down
109 changes: 109 additions & 0 deletions app/Http/Controllers/Contacts/PetsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace App\Http\Controllers\Contacts;

use App\Pet;
use App\Contact;
use App\PetCategory;
use App\Http\Controllers\Controller;
use App\Http\Requests\People\PetsRequest;

class PetsController extends Controller
{
/**
* Get all the pet categories.
*/
public function getPetCategories()
{
$petCategoriesData = collect([]);

$petCategories = PetCategory::all();

foreach ($petCategories as $petCategory) {
$data = [
'id' => $petCategory->id,
'name' => $petCategory->name,
'edit' => false,
];
$petCategoriesData->push($data);
}

return $petCategoriesData;
}

/**
* Get all the pets for this contact.
* @param Contact $contact
*/
public function get(Contact $contact)
{
$petsCollection = collect([]);
$pets = $contact->pets;

foreach ($pets as $pet) {
$data = [
'id' => $pet->id,
'name' => $pet->name,
'pet_category_id' => $pet->pet_category_id,
'category_name' => $pet->petCategory->name,
'edit' => false,
];
$petsCollection->push($data);
}

return $petsCollection;
}

/**
* Store the pet.
*/
public function store(PetsRequest $request, Contact $contact)
{
$pet = $contact->pets()->create(
$request->only([
'pet_category_id',
'name',
])
+ [
'account_id' => auth()->user()->account->id,
]
);

return $data = [
'id' => $pet->id,
'name' => $pet->name,
'pet_category_id' => $pet->pet_category_id,
'category_name' => $pet->petCategory->name,
'edit' => false,
];
}

/**
* Update the pet.
*/
public function update(PetsRequest $request, Contact $contact, Pet $pet)
{
$pet->update(
$request->only([
'pet_category_id',
'name',
])
+ [
'account_id' => auth()->user()->account->id,
]
);

return $data = [
'id' => $pet->id,
'name' => $pet->name,
'pet_category_id' => $pet->pet_category_id,
'category_name' => $pet->petCategory->name,
'edit' => false,
];
}

public function trash(Contact $contact, Pet $pet)
{
$pet->delete();
}
}
31 changes: 31 additions & 0 deletions app/Http/Requests/People/PetsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests\People;

use Illuminate\Foundation\Http\FormRequest;

class PetsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'max:255|nullable',
'pet_category_id' => 'integer',
];
}
}
1 change: 1 addition & 0 deletions app/Jobs/ExportAccountAsSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ExportAccountAsSQL
'oauth_personal_access_clients',
'oauth_refresh_tokens',
'password_resets',
'pet_categories',
'sessions',
'statistics',
'subscriptions',
Expand Down
57 changes: 57 additions & 0 deletions app/Pet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Pet extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];

/**
* Get the account record associated with the gift.
*
* @return BelongsTo
*/
public function account()
{
return $this->belongsTo(Account::class);
}

/**
* Get the contact record associated with the gift.
*
* @return BelongsTo
*/
public function contact()
{
return $this->belongsTo(Contact::class);
}

/**
* Get the contact record associated with the gift.
*
* @return BelongsTo
*/
public function petCategory()
{
return $this->belongsTo(PetCategory::class);
}

/**
* Set the name to null if it's an empty string.
*
* @param string $value
* @return void
*/
public function setNameAttribute($value)
{
$this->attributes['name'] = $value ?: null;
}
}
39 changes: 39 additions & 0 deletions app/PetCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class PetCategory extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];

protected $table = 'pet_categories';

/**
* Scope a query to only include pet categories that are considered `common`.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCommon($query)
{
return $query->where('is_common', 1);
}

/**
* Get the name of the pet's category.
*
* @param string $value
* @return string
*/
public function getNameAttribute($value)
{
return $value;
}
}
7 changes: 7 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Route;
use App\Day;
use App\Pet;
use App\Debt;
use App\Gift;
use App\Note;
Expand Down Expand Up @@ -124,6 +125,12 @@ public function boot()
->where('id', $value)
->firstOrFail();
});

Route::bind('pet', function ($value, $route) {
return Pet::where('account_id', auth()->user()->account_id)
->where('id', $value)
->firstOrFail();
});
}

/**
Expand Down
6 changes: 3 additions & 3 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'prefix' => env('DB_PREFIX', ''),
],

'mysql' => [
Expand All @@ -61,7 +61,7 @@
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'prefix' => env('DB_PREFIX', ''),
'strict' => false,
'engine' => null,
],
Expand All @@ -86,7 +86,7 @@
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix' => env('DB_PREFIX', ''),
'schema' => 'public',
],

Expand Down
44 changes: 44 additions & 0 deletions database/migrations/2017_12_24_115641_create_pets_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pets', function (Blueprint $table) {
$table->increments('id');
$table->integer('account_id');
$table->integer('contact_id');
$table->integer('pet_category_id');
$table->string('name')->nullable();
$table->timestamps();
});

Schema::create('pet_categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->boolean('is_common');
$table->timestamps();
});

DB::table('pet_categories')->insert(['name' => 'reptile', 'is_common' => false]);
DB::table('pet_categories')->insert(['name' => 'bird', 'is_common' => false]);
DB::table('pet_categories')->insert(['name' => 'cat', 'is_common' => true]);
DB::table('pet_categories')->insert(['name' => 'dog', 'is_common' => true]);
DB::table('pet_categories')->insert(['name' => 'fish', 'is_common' => true]);
DB::table('pet_categories')->insert(['name' => 'hamster', 'is_common' => false]);
DB::table('pet_categories')->insert(['name' => 'horse', 'is_common' => false]);
DB::table('pet_categories')->insert(['name' => 'rabbit', 'is_common' => false]);
DB::table('pet_categories')->insert(['name' => 'rat', 'is_common' => false]);
DB::table('pet_categories')->insert(['name' => 'small_animal', 'is_common' => false]);
DB::table('pet_categories')->insert(['name' => 'other', 'is_common' => false]);
}
}
Loading