Skip to content

Commit

Permalink
Admin panel was added. List of users, products, orders with status ch…
Browse files Browse the repository at this point in the history
…ange was added
  • Loading branch information
vilgefortzz committed Jun 2, 2017
1 parent e054661 commit f371906
Show file tree
Hide file tree
Showing 26 changed files with 1,314 additions and 18 deletions.
11 changes: 11 additions & 0 deletions app/Http/Controllers/Admin/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CategoryController extends Controller
{
//
}
54 changes: 54 additions & 0 deletions app/Http/Controllers/Admin/OrderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Order;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class OrderController extends Controller
{
public function index(){

$orders = Order::orderBy('created_at', 'desc')->paginate(10);
return view('admin.orders.orders', compact('orders'));
}

public function indexPending(){

$orders = Order::where('status', 'Pending')->orderBy('created_at', 'desc')->paginate(10);
return view('admin.orders.orders', compact('orders'));
}

public function indexPreparingToSend(){

$orders = Order::where('status', 'Preparing to send')->orderBy('created_at', 'desc')->paginate(10);
return view('admin.orders.orders', compact('orders'));
}

public function indexWaitingForPayment(){

$orders = Order::where('status', 'Waiting for payment')->orderBy('created_at', 'desc')->paginate(10);
return view('admin.orders.orders', compact('orders'));
}

public function indexSend(){

$orders = Order::where('status', 'Send')->orderBy('created_at', 'desc')->paginate(10);
return view('admin.orders.orders', compact('orders'));
}

public function indexCompleted(){

$orders = Order::where('status', 'Completed')->orderBy('created_at', 'desc')->paginate(10);
return view('admin.orders.orders', compact('orders'));
}

public function updateStatus(Order $order, Request $request){

$order->status = $request->status;
$order->save();

return back();
}
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Product;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ProductController extends Controller
{
public function index(){

$products = Product::paginate(5);
return view('admin.products.products', compact('products'));
}
}
11 changes: 11 additions & 0 deletions app/Http/Controllers/Admin/ReviewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ReviewController extends Controller
{
//
}
11 changes: 11 additions & 0 deletions app/Http/Controllers/Admin/SubcategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SubcategoryController extends Controller
{
//
}
11 changes: 11 additions & 0 deletions app/Http/Controllers/Admin/SubscribeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SubscribeController extends Controller
{
//
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers\Admin;

use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
public function index(){

$users = User::paginate(20);
return view('admin.users.users', compact('users'));
}
}
11 changes: 10 additions & 1 deletion app/Http/Controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public function store(Request $request){
/*
* Validate data
*/

$this->validate($request, [
'email' => 'required|email|max:255',
'first_name' => 'required|min:3|max:30',
Expand All @@ -73,6 +72,16 @@ public function store(Request $request){
// Create order
$order = new Order();

// Fill essential data
$order->email = $request->email;
$order->first_name = $request->first_name;
$order->last_name = $request->last_name;
$order->street = $request->street;
$order->postal_code = $request->postal_code;
$order->city = $request->city;
$order->country = $request->country;
$order->phone_number = $request->phone_number;

$discount = 0;

if (Auth::check()){
Expand Down
27 changes: 27 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ public function showPendingOrders(User $user){
return view('users.orders', compact('orders'));
}

public function showPreparingToSendOrders(User $user){

$orders = Order::where('user_id', $user->id)
->where('status', 'Preparing to send')
->orderBy('created_at', 'desc')->paginate(2);

return view('users.orders', compact('orders'));
}

public function showWaitingForPaymentOrders(User $user){

$orders = Order::where('user_id', $user->id)
->where('status', 'Waiting for payment')
->orderBy('created_at', 'desc')->paginate(2);

return view('users.orders', compact('orders'));
}

public function showSendOrders(User $user){

$orders = Order::where('user_id', $user->id)
->where('status', 'Send')
->orderBy('created_at', 'desc')->paginate(2);

return view('users.orders', compact('orders'));
}

public function showCompletedOrders(User $user){

$orders = Order::where('user_id', $user->id)
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ class Kernel extends HttpKernel
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'admin' => 'App\Http\Middleware\Admin'
];
}
24 changes: 24 additions & 0 deletions app/Http/Middleware/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Middleware;

use Auth;
use Closure;

class Admin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check() && Auth::user()->admin) {
return $next($request);
}
return redirect('/');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function up()
$table->string('country')->nullable();
$table->string('phone_number')->nullable();
$table->float('discount')->unsigned()->default('20');
$table->boolean('admin')->default(false);
$table->rememberToken();
$table->timestamps();
});
Expand Down
8 changes: 8 additions & 0 deletions database/migrations/2017_03_05_190202_create_orders_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public function up()
$table->increments('id');
$table->float('total_paid')->unsigned();
$table->string('status');
$table->string('email');
$table->string('first_name');
$table->string('last_name');
$table->string('street');
$table->string('postal_code');
$table->string('city');
$table->string('country');
$table->string('phone_number');
$table->timestamps();

$table->integer('user_id')->index()->unsigned()->nullable();
Expand Down
12 changes: 12 additions & 0 deletions database/seeds/UsersTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class UsersTableSeeder extends Seeder
public function run()
{

/*
* Create admin
*/
factory(User::class)->create([

'username' => 'Admin',
'email' => 'admin@admin.com',
'password' => bcrypt('admin'),
'admin' => true

]);

factory(User::class)->create([

'username' => 'vilgefortzz',
Expand Down
318 changes: 315 additions & 3 deletions public/css/app.css

Large diffs are not rendered by default.

Loading

0 comments on commit f371906

Please sign in to comment.