Skip to content
Open
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
24 changes: 21 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Contracts\Validation\Validator as validate;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class RegisterController extends Controller
{
Expand Down Expand Up @@ -49,16 +52,29 @@ public function __construct()
*/
protected function validator(array $data)
{
return Validator::make($data, [
$validator = Validator::make($data, [
'firstname' => ['required', 'string', 'max:255'],
'lastname' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'username' => ['required', 'string', 'max:255'],
'phone' => ['required', 'string', 'max:255'],
'is_male' => ['boolean'],
'birthdate' => ['required', 'date'],
// 'default_address_id' => ['required', 'bigint', 'max:255'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
return $validator;
}

protected function failedValidation(validate $validator)
{
dd('in validator');
throw new HttpResponseException(
response()->json([
'success' => false,
'message' => $validator->errors()->first(),
], 400)
);
}

/**
Expand All @@ -69,14 +85,16 @@ protected function validator(array $data)
*/
protected function create(array $data)
{
return User::create([
$user = User::create([
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'username' => $data['username'],
'email' => $data['email'],
'phone' => $data['phone'],
'is_male' => $data['gender'],
'is_male' => $data['is_male'],
'birthdate' => $data['birthdate'],
'password' => Hash::make($data['password']),
]);
return $user;
}
}
12 changes: 7 additions & 5 deletions app/Http/Controllers/Dashboard/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Product\AddProductRequest;
use App\Http\Requests\Product\UpdateProductRequest;
use App\Models\Area;
use App\Models\Product;

class ProductController extends Controller
Expand All @@ -24,7 +25,7 @@ public function index()

$products = $query->paginate(3);

return view('products.index', compact('products'));
return view('admin.products.index', compact('products'));
}

/**
Expand All @@ -34,8 +35,9 @@ public function index()
*/
public function create()
{
//$categories = Category::all();
return view('products.create');
$categories = [];
$areas = Area::all(['id','name']);
return view('admin.products.create',compact('categories','areas'));
}

/**
Expand Down Expand Up @@ -71,7 +73,7 @@ public function store(AddProductRequest $request)
*/
public function show(Product $product)
{
return view('products.show', compact('product'));
return view('admin.products.show', compact('product'));
}

/**
Expand All @@ -82,7 +84,7 @@ public function show(Product $product)
*/
public function edit($product)
{
return view('products.edit', compact('product'));
return view('admin.products.edit', compact('product'));
}

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

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Translatable\HasTranslations;

class Category extends Model
{
use HasFactory,SoftDeletes, HasTranslations;

protected $fillable=[
'name',
'parent_id',
];

public $translatable = ['name'];

public function categoryParent()
{
return $this->belongsTo(Category::class,"parent_id");
}

public function categoryChilds()
{
return $this->hasMany(Category::class);
}

public function product()
{
return $this->hasMany(Product::class);
}
}
26 changes: 26 additions & 0 deletions app/Models/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Translatable\HasTranslations;

class Currency extends Model
{
use HasFactory,SoftDeletes, HasTranslations;

protected $fillable = [
'name',
'symbol',
'rate',
];

public $translatable = ['name'];

public function products()
{
return $this->hasMany(Product::class);
}
}
9 changes: 2 additions & 7 deletions app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Product extends Model implements HasMedia

public $translatable = ['name', 'description'];

public function scopeCategory($query, $category)
public function scopeCategorySort($query, $category)
{
return $query->where('category_id', $category->id);
return $query->sortBy('category_id');
}

public function scopeRate($query)
Expand Down Expand Up @@ -70,11 +70,6 @@ public function owner()
return $this->belongsTo(Owner::class);
}

// public function Invoices()
// {
// return $this->belongsToMany(Invoice::class);
// }

public function orders()
{
return $this->belongsToMany(Order::class);
Expand Down
1 change: 1 addition & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class User extends Authenticatable
protected $fillable = [
'firstname',
'lastname',
'username',
'email',
'phone',
'is_male',
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions database/migrations/2022_08_10_175111_create_categories_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');

$table->foreignId('parent_id')->nullable()->constrained('categories');

$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
};
37 changes: 37 additions & 0 deletions database/migrations/2022_08_10_194118_create_currencies_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('currencies', function (Blueprint $table) {
$table->id();

$table->json('name');
$table->string('symbol');
$table->decimal('rate');

$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('currencies');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public function up()
$table->integer('price')->unsigned();
$table->integer('quantity')->unsigned()->default(0);

$table->foreignId('currency_id')/*->constrained()*/;
$table->foreignId('category_id')/*->constrained()*/;
$table->foreignId('area_id')/*->constrained()*/;
$table->foreignId('currency_id')->constrained();
$table->foreignId('category_id')->constrained();
$table->foreignId('area_id')->constrained();
$table->foreignId('owner_id')->constrained('users');

$table->timestamps();
Expand Down
22 changes: 22 additions & 0 deletions database/seeders/CategorySeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Database\Seeders;

use App\Models\Category;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class CategorySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Category::create(['id' => '1', 'name' => ['en' => 'electronics', 'ar' => 'إلكترونيات']]);
Category::create(['id' => '2', 'name' => ['en' => 'clothes', 'ar' => 'ملابس']]);

}
}
21 changes: 21 additions & 0 deletions database/seeders/CurrencySeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Database\Seeders;

use App\Models\Currency;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class CurrencySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Currency::create(['id' => '1', 'name' => ['en' => 'syrian pounds', 'ar' => 'ليرة سورية'],'symbol' => 'SP','rate' => 1]);
Currency::create(['id' => '2', 'name' => ['en' => 'us dollars', 'ar' => 'دولار أمريكي'],'symbol' => '$','rate' => 4500]);
}
}
Loading