laravel-ecommerce-example
laravel-ecommerce-example copied to clipboard
No Products Passed Through To Order BREAD when Overwriting Voyager
I've run into an issue when creating the 'Orders' view on Voyager. I am overwriting the voyager view 'read.blade.php' for my order table. I also have my BREAD linked to a Controller called OrdersController.php, just like part 18 in the series.
Here is my OrderController.php:
<?php
namespace App\Http\Controllers\Voyager;
use App\Order;
use Validator;
use App\iamlush;
use Illuminate\Http\Request;
use TCG\Voyager\Facades\Voyager;
use TCG\Voyager\Events\BreadDataAdded;
use TCG\Voyager\Events\BreadDataUpdated;
use TCG\Voyager\Http\Controllers\VoyagerBaseController;
class OrdersController extends VoyagerBaseController
{
//***************************************
// _____
// | __ \
// | |__) |
// | _ /
// | | \ \
// |_| \_\
//
// Read an item of our Data Type B(R)EAD
//
//****************************************
public function show(Request $request, $id)
{
$slug = $this->getSlug($request);
$dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();
$isSoftDeleted = false;
if (strlen($dataType->model_name) != 0) {
$model = app($dataType->model_name);
// Use withTrashed() if model uses SoftDeletes and if toggle is selected
if ($model && in_array(SoftDeletes::class, class_uses_recursive($model))) {
$model = $model->withTrashed();
}
if ($dataType->scope && $dataType->scope != '' && method_exists($model, 'scope'.ucfirst($dataType->scope))) {
$model = $model->{$dataType->scope}();
}
$dataTypeContent = call_user_func([$model, 'findOrFail'], $id);
if ($dataTypeContent->deleted_at) {
$isSoftDeleted = true;
}
} else {
// If Model doest exist, get data from table name
$dataTypeContent = DB::table($dataType->name)->where('id', $id)->first();
}
// Replace relationships' keys for labels and create READ links if a slug is provided.
$dataTypeContent = $this->resolveRelations($dataTypeContent, $dataType, true);
// If a column has a relationship associated with it, we do not want to show that field
$this->removeRelationshipField($dataType, 'read');
// Check permission
$this->authorize('read', $dataTypeContent);
// Check if BREAD is Translatable
$isModelTranslatable = is_bread_translatable($dataTypeContent);
// Eagerload Relations
$this->eagerLoadRelations($dataTypeContent, $dataType, 'read', $isModelTranslatable);
$view = 'voyager::bread.read';
if (view()->exists("voyager::$slug.read")) {
$view = "voyager::$slug.read";
}
$order = Order::find($id);
$products = $order->iamlush; // this is my version of 'products'
return Voyager::view($view, compact('dataType', 'dataTypeContent', 'isModelTranslatable', 'isSoftDeleted', 'products'));
}
}
Here you can see the section that takes the order and the products with it:
$order = Order::find($id); (this gets the order id)
$products = $order->iamlush; (this gets the product info and is there retutned below)
return Voyager::view($view, compact('dataType', 'dataTypeContent', 'isModelTranslatable', 'isSoftDeleted', 'products'));
My override 'read.blade.php' is the same as the normal apart from one section:
<div class="panel-heading" style="border-bottom:0;">
<h3 class="panel-title">Products In Order</h3>
</div>
<div class="panel-body" style="padding-top:0;">
<ul>
@foreach ($products as $product)
<li style="margin-bottom: 10px">
<div>Product Id: {{ $product->id }}</div>
<div>Product Name: {{ $product->name }}</div>
<div>Product Price: {{ $product->presentPrice() }}</div>
<div>Product Quantity: {{ $product->pivot->quantity }}</div>
</li>
@endforeach
</ul>
</div>
This should return all the data held in my database but instead, I get this error:

To see what was being output I added dd() just before the return:
$order = Order::find($id); (this gets the order id)
$products = $order->iamlushes; (this gets the product info and is there retutned below)
dd($products)
return Voyager::view($view, compact('dataType', 'dataTypeContent', 'isModelTranslatable', 'isSoftDeleted', 'products'));
And changed the '$order->iamlush' to different things here is the output:
$order = Order::find($id);
$products = $order->iamlush;
dd($products);

$order = Order::find($id);
$products = $order->iamlushes;
dd($products);

$order = Order::find($id);
$products = $order->products;
dd($products);

$order = Order::find($id);
$products = $order->product;
dd($products);

Here is my GitLab Repo: https://gitlab.com/rossi99/salonwebsite
Can SOMEONE HELP ME?!