Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Products Passed Through To Order BREAD when Overwriting Voyager #91

Open
rossi99 opened this issue Jul 12, 2020 · 0 comments
Open

No Products Passed Through To Order BREAD when Overwriting Voyager #91

rossi99 opened this issue Jul 12, 2020 · 0 comments

Comments

@rossi99
Copy link

rossi99 commented Jul 12, 2020

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:

Screenshot 2020-07-12 at 17 22 21

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);

Screenshot 2020-07-12 at 17 29 09

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

dd($products);

Screenshot 2020-07-12 at 17 29 09

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

dd($products);

Screenshot 2020-07-12 at 17 30 08

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

dd($products);

Screenshot 2020-07-12 at 17 31 00

Here is my GitLab Repo: https://gitlab.com/rossi99/salonwebsite

Can SOMEONE HELP ME?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant