Skip to content

Commit

Permalink
A few problems were fixed in backend, also was improved appearance of…
Browse files Browse the repository at this point in the history
… app
  • Loading branch information
vilgefortzz committed Apr 16, 2017
1 parent d80bfad commit 02423be
Show file tree
Hide file tree
Showing 36 changed files with 1,028 additions and 178 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Homestead.json
Homestead.yaml
.env
_ide_helper.php
config/ide-helper.php
4 changes: 2 additions & 2 deletions app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class Category extends Model
{
public function products()
public function subcategories()
{
return $this->hasMany('App\Product');
return $this->hasMany('App\Subcategory');
}
}
27 changes: 22 additions & 5 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Auth;

use App\Cart;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -62,10 +63,26 @@ protected function validator(array $data)
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);

/*
* Create new user
*/
$user = new User();
$user->name = $data['name'];
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();

/*
* Create cart for new user
*/
$cart = new Cart();

/*
* Add this cart to newly created user
*/
$user->cart()->save($cart);

return $user;
}
}
10 changes: 10 additions & 0 deletions app/Http/Controllers/SubcategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SubcategoryController extends Controller
{
//
}
4 changes: 2 additions & 2 deletions app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class Product extends Model
{
public function category()
public function subcategory()
{
return $this->belongsTo('App\Category');
return $this->belongsTo('App\Subcategory');
}
}
5 changes: 4 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use DB;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -13,7 +14,9 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
//
if (DB::connection() instanceof \Illuminate\Database\SQLiteConnection) {
DB::statement(DB::raw('PRAGMA foreign_keys=1'));
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions app/Subcategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Subcategory extends Model
{
public function category()
{
return $this->belongsTo('App\Category');
}

public function products()
{
return $this->hasMany('App\Product');
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"php": ">=5.6.4",
"barryvdh/laravel-debugbar": "v2.3.2",
"barryvdh/laravel-ide-helper": "v2.3.2",
"doctrine/dbal": "2.6.x-dev",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "~5.0"
Expand Down
Loading

0 comments on commit 02423be

Please sign in to comment.