Skip to content

Commit

Permalink
Adding products to the admin panel and changing the buycraft theme
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 24, 2018
1 parent 26178f6 commit b1e4ad6
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 32 deletions.
20 changes: 16 additions & 4 deletions app/Http/Controllers/Admin/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function store(Request $request)
*/
public function show(Category $category)
{
//
}

/**
Expand All @@ -73,7 +72,8 @@ public function show(Category $category)
*/
public function edit(Category $category)
{
//
return view('admin.pages.category.edit')->with(compact("category"));

}

/**
Expand All @@ -85,7 +85,16 @@ public function edit(Category $category)
*/
public function update(Request $request, Category $category)
{
//
$category->name = request("name");
$category->desc = request("desc");
$category->short_desc = request("short_desc");
$category->visible = (request("visible") != null);
$category->featured = (request("featured") != null);
$category->parent_id = request("parent");

$category->save();
session()->flash('good', "'$category->name' saved");
return redirect()->route('admin.Categories');
}

/**
Expand All @@ -96,6 +105,9 @@ public function update(Request $request, Category $category)
*/
public function destroy(Category $category)
{
//
session()->flash('good', "'$category->name' deleted (All products in this category will need to have a new one set)");
$category->delete();

return redirect()->route('admin.Categories');
}
}
7 changes: 4 additions & 3 deletions app/Http/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Http\Controllers\Admin;

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

class CategoryController extends Controller
class ProductController extends Controller
{
public function __construct()
{
Expand All @@ -19,8 +20,8 @@ public function __construct()
*/
public function index()
{
$categories = Category::paginate(15);
return view('admin.pages.category.index')->with(["categories"=>$categories]);
$products = Product::paginate(15);
return view('admin.pages.product.index')->with(["products"=>$products]);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

class Order extends Model
{
public function getHead(){
$json = file_get_contents("https://api.mojang.com/users/profiles/minecraft/".$this->username."?at=".strtotime($this->created_at));
$arr = json_decode($json, true);
if(isset($arr["error"])){
return "https://crafatar.com/renders/head/8667ba71-b85a-4004-af54-457a9734eed7";
}else{
return "https://crafatar.com/renders/head/".$arr["id"]."?overlay";
}
}
public function lastIPN(){
return(json_decode($this->postdata,true));
}
Expand Down Expand Up @@ -53,6 +62,11 @@ public static function moneyReceived($start, $end){
return Order::between($start,$end,false)->select(DB::raw("SUM(`total`) AS Total"))->get()->first()->Total;
}

public static function last($num)
{
return \App\Order::orderBy('created_at', 'desc')->take($num)->get();
}

public static function lastDays($days)
{
return Order::between(\Carbon\Carbon::now()->subDays($days), \Carbon\Carbon::now()->addDays(1));
Expand Down
107 changes: 107 additions & 0 deletions resources/views/admin/pages/category/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
@extends('admin.layout')

@section('title')
Edit {{$category->name}}
@endsection

@section('desc')
Made a mistake? No Prob-Lamo
@endsection

@section('content')

<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Editing {{$category->name}}</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form" action="{{route('admin.Categories.edit',["category"=>$category])}}" method="POST">
{{csrf_field()}}
<div class="box-body">
<div class="form-group">
<label for="name">Name</label>
<input class="form-control" name="name" id="name" placeholder="Category Name" value="{{$category->name}}" required>
</div>

<div class="form-group">
<label for="desc">Description</label>
<textarea id="desc" name="desc" rows="10" cols="80" style="visibility: hidden; display: none;" value="{{$category->desc}}">
{{$category->desc}}
</textarea>
</div>



<div class="form-group">
<label for="short_desc">Short Description</label>
<input class="form-control" name="short_desc" id="short_desc" placeholder="Short category description" value="{{$category->short_desc}}" required>
</div>

<div class="form-group">
<label for="visible">Visible</label>
<input type="checkbox" id="visible" value="1" @if($category->visible == 1) checked="" @endif name="visible">
</div>
<div class="form-group">
<label for="featured">Featured</label>
<input type="checkbox" id="featured" value="1" @if($category->featured == 1) checked="" @endif name="featured">
</div>
<div class="form-group">
<label for="parent">Parent Category</label>
<br>
<select class="parent" id="parent" name="parent">
<option value="">None</option>
@foreach(\App\Category::all() as $category2)
@if($category2->parent_id == null)
<option value="{{$category2->id}}" @if($category->parent_id == $category2->id) selected @endif>{{$category2->name}}</option>
@endif
@endforeach
</select>
</div>
</div>
<!-- /.box-body -->

<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
<!-- /.box -->
</div>
@endsection

@section('head')
<link rel="stylesheet" href="/admin/plugins/iCheck/square/blue.css">
<link rel="stylesheet" href="/admin/bower_components/select2/dist/css/select2.min.css">
<style type="text/css">
.select2-container {
margin: 0;
}
</style>
@endsection

@section('extra')
<script src="/admin/plugins/iCheck/icheck.min.js"></script>
<script src="/admin/bower_components/ckeditor/ckeditor.js"></script>
<script src="/admin/bower_components/select2/dist/js/select2.full.min.js"></script>

<script type="text/javascript">
$(function () {
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace('desc');
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' /* optional */
});
$('.parent').select2();
})
</script>
@endsection
2 changes: 1 addition & 1 deletion resources/views/admin/pages/category/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<td>{{$category->name}}</td>
<td>{{$category->short_desc}}</td>
@if(\Auth::user()->can('list category') || \Auth::user()->can('create category'))
<td><a class="btn btn-primary" href="{{route('admin.Categories.view', ['category' => $category])}}">@can('edit categorys') Edit @else View @endcan</a> @can('delete category')<a href="{{route('admin.Categories.delete', ['category' => $category])}}" class="btn btn-danger">Delete</a>@endcan</td>
<td><a class="btn btn-primary" href="{{route('admin.Categories.edit', ['category' => $category])}}">@can('edit categorys') Edit @else View @endcan</a> @can('delete category')<a href="{{route('admin.Categories.delete', ['category' => $category])}}" class="btn btn-danger">Delete</a>@endcan</td>
@endif
</tr>
@endforeach
Expand Down
6 changes: 4 additions & 2 deletions resources/views/admin/pages/order/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@
<th>ID</th>
<th>Username</th>
<th>Status</th>
<th>Transaction ID</th>
<th>Total</th>
<th>Actions</th>
</tr>
@foreach ($orders as $order)
<tr>
<td>{{$order->id}}</td>
<td>{{$order->username}}</td>
<td>{{$order->status}}</td>
<td>{{$order->status}}</td>
<td>{{$order->txid}}</td>
<td>{{$order->total}} {{$order->currency}}</td>

<td>
<a class="btn btn-primary" href="#">View</a>
<a href="#" class="btn btn-danger">Delete</a>
<!-- <a href="#" class="btn btn-danger">Delete</a> -->
</td>
</tr>
@endforeach
Expand Down
107 changes: 107 additions & 0 deletions resources/views/admin/pages/product/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
@extends('admin.layout')

@section('title')
Edit {{$category->name}}
@endsection

@section('desc')
Made a mistake? No Prob-Lamo
@endsection

@section('content')

<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Editing {{$category->name}}</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form" action="{{route('admin.Categories.edit',["category"=>$category])}}" method="POST">
{{csrf_field()}}
<div class="box-body">
<div class="form-group">
<label for="name">Name</label>
<input class="form-control" name="name" id="name" placeholder="Category Name" value="{{$category->name}}" required>
</div>

<div class="form-group">
<label for="desc">Description</label>
<textarea id="desc" name="desc" rows="10" cols="80" style="visibility: hidden; display: none;" value="{{$category->desc}}">
{{$category->desc}}
</textarea>
</div>



<div class="form-group">
<label for="short_desc">Short Description</label>
<input class="form-control" name="short_desc" id="short_desc" placeholder="Short category description" value="{{$category->short_desc}}" required>
</div>

<div class="form-group">
<label for="visible">Visible</label>
<input type="checkbox" id="visible" value="1" @if($category->visible == 1) checked="" @endif name="visible">
</div>
<div class="form-group">
<label for="featured">Featured</label>
<input type="checkbox" id="featured" value="1" @if($category->featured == 1) checked="" @endif name="featured">
</div>
<div class="form-group">
<label for="parent">Parent Category</label>
<br>
<select class="parent" id="parent" name="parent">
<option value="">None</option>
@foreach(\App\Category::all() as $category2)
@if($category2->parent_id == null)
<option value="{{$category2->id}}" @if($category->parent_id == $category2->id) selected @endif>{{$category2->name}}</option>
@endif
@endforeach
</select>
</div>
</div>
<!-- /.box-body -->

<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
<!-- /.box -->
</div>
@endsection

@section('head')
<link rel="stylesheet" href="/admin/plugins/iCheck/square/blue.css">
<link rel="stylesheet" href="/admin/bower_components/select2/dist/css/select2.min.css">
<style type="text/css">
.select2-container {
margin: 0;
}
</style>
@endsection

@section('extra')
<script src="/admin/plugins/iCheck/icheck.min.js"></script>
<script src="/admin/bower_components/ckeditor/ckeditor.js"></script>
<script src="/admin/bower_components/select2/dist/js/select2.full.min.js"></script>

<script type="text/javascript">
$(function () {
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace('desc');
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' /* optional */
});
$('.parent').select2();
})
</script>
@endsection
Loading

0 comments on commit b1e4ad6

Please sign in to comment.