Skip to content

Commit

Permalink
add avalaible type
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzahjamad committed Oct 20, 2017
1 parent c7ddff6 commit a2478ae
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 7 deletions.
12 changes: 12 additions & 0 deletions app/AvailableBatchType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AvailableBatchType extends Model
{
protected $fillable = [
'name',
];
}
5 changes: 5 additions & 0 deletions app/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public function orders()
{
return $this->hasMany(Order::class);
}

public function types()
{
return $this->hasMany(AvailableBatchType::class);
}
}
16 changes: 14 additions & 2 deletions app/Http/Controllers/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use App\Batch;
use App\Order;
use App\AvailableBatchType;

class BatchController extends Controller
{
Expand Down Expand Up @@ -47,8 +48,6 @@ public function store(Request $request)
'name'=>'required',
]);



$batch = new Batch;
$batch->name = $request->name;

Expand All @@ -65,6 +64,19 @@ public function store(Request $request)
$batch->save();



if ($request->type) {
foreach ($request->type as $color => $sleeve) {
foreach ($sleeve as $k => $v) {
$available_type = new AvailableBatchType;
$available_type->batch_id = $batch->id;
$available_type->name = ucwords($color .' '.str_replace("_"," ",$k));
$available_type->save();
}
}
}


return redirect('batches');
}

Expand Down
10 changes: 8 additions & 2 deletions app/Http/Controllers/RecipientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ public function __construct()
*/
public function create($bid)
{
$shirts = $this->getShirts();
$sizes = $this->getSizes();
$batch = Batch::find($bid);
$types = $batch->types->pluck('name')->toArray();
$shirts = collect($this->getShirts())->filter(function ($value, $key) use ($types) {
return in_array($value->name, $types);
});
return view('recipient-modify', compact('shirts', 'sizes', 'bid', 'batch'));
}

Expand Down Expand Up @@ -100,9 +103,12 @@ public function store(Request $request, $bid)
*/
public function edit($bid, $id)
{
$shirts = $this->getShirts();
$sizes = $this->getSizes();
$batch = Batch::find($bid);
$types = $batch->types->pluck('name')->toArray();
$shirts = collect($this->getShirts())->filter(function ($value, $key) use ($types) {
return in_array($value->name, $types);
});
$orders = Order::where('recipient_id', $id)->get();
return view('recipient-modify', compact('shirts', 'sizes', 'bid', 'batch', 'orders'));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

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

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

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('available_batch_types');
}
}
29 changes: 29 additions & 0 deletions resources/views/batch-modify.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@
<input type="file" name="design">
<p class="help-block">Put design over here</p>
</div>
<hr>

<h5><b>Type*</b></h5>

<div class="checkbox">
<label>
<input type="checkbox" name="type[black][long_sleeve]" checked> Black Long Sleeve
</label>
</div>

<div class="checkbox">
<label>
<input type="checkbox" name="type[black][short_sleeve]" checked> Black Short Sleeve
</label>
</div>


<div class="checkbox">
<label>
<input type="checkbox" name="type[white][long_sleeve]" checked> White Long Sleeve
</label>
</div>


<div class="checkbox">
<label>
<input type="checkbox" name="type[white][short_sleeve]" checked> White Short Sleeve
</label>
</div>

<button type="submit" class="btn btn-default">Save</button>
{!! Form::close() !!}
Expand Down
6 changes: 3 additions & 3 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
<ul class="dropdown-menu" role="menu">
<li>
@if(Auth::user()->have_access)
<a href="/users">
All Users
</a>
<a href="/batches">
All Batches
</a>
<a href="/users">
All Users
</a>
@endif
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
Expand Down

0 comments on commit a2478ae

Please sign in to comment.