Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
0 / 0 |
CRAP | |
100.00% |
0 / 0 |
| ProductController | |
100.00% |
1 / 1 |
|
100.00% |
8 / 8 |
11 | |
100.00% |
0 / 0 |
| index | |
100.00% |
1 / 1 |
2 | |
100.00% |
0 / 0 |
|||
| anonymous function | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
| create | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
| store | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
| show | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
| edit | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
| update | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
| destroy | |
100.00% |
1 / 1 |
3 | |
100.00% |
0 / 0 |
|||
| <?php | |
| namespace Mtc\Shop\Http\Controllers\Admin; | |
| use App\Http\Controllers\Controller; | |
| use App\Http\Requests; | |
| use Illuminate\Http\Request; | |
| use Mtc\Core\Admin\Builder; | |
| use Mtc\Core\Admin\ItemBuilder; | |
| use Mtc\Core\Admin\Node; | |
| use Mtc\Shop\Http\Requests\Admin\StoreProduct; | |
| use Mtc\Shop\Product; | |
| class ProductController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index() | |
| { | |
| return (new Builder('products', Product::query())) | |
| ->columns([ | |
| 'id' => trans('fields.id'), | |
| 'node.title' => trans('fields.title'), | |
| 'node.status' => trans('fields.status'), | |
| 'stock_enabled' => trans('fields.stock_enabled'), | |
| 'updated_at' => trans('fields.updated_at') | |
| ]) | |
| ->data([ | |
| 'node.title' => function($item) { | |
| return $item->node->title; | |
| }, | |
| 'stock_enabled' => function($item) { | |
| return $item->stock_enabled ? 'Yes' : 'No'; | |
| }, | |
| 'node.status' => function($item) { | |
| return ucfirst($item->node->status); | |
| } | |
| ]) | |
| ->view(); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create() | |
| { | |
| return (new ItemBuilder('products', new Product, new Node)) | |
| ->view('shop::admin.product.form'); | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(StoreProduct $request, Product $product, Node $node) | |
| { | |
| $product->fill($request->input('item', []))->save(); | |
| $node->fill($request->input('node', [])); | |
| $product->node()->save($node); | |
| return redirect(route('products.index')); | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function show($id) | |
| { | |
| return Product::with('node')->findOrFail($id); | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit(Product $product) | |
| { | |
| return (new ItemBuilder('products', $product, $product->node)) | |
| ->view('shop::admin.product.form'); | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function update(StoreProduct $request, Product $product) | |
| { | |
| $product->fill($request->input('item', [])); | |
| $product->node->fill($request->input('node', []))->save(); | |
| $product->save(); | |
| return redirect(route('products.index')); | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy(Request $request, Product $product) | |
| { | |
| if ($product->node) { | |
| $product->node->delete(); | |
| } | |
| $product->delete(); | |
| if ($request->ajax()) { | |
| return response('success', 200); | |
| } | |
| $request->session()->flash('success', "{$product->title} has been deleted."); | |
| return redirect()->back(); | |
| } | |
| } |