laravel-ecommerce-example
laravel-ecommerce-example copied to clipboard
Bad Method: App\Http\Controllers\Voyager\OrdersController::getRelationships
When I go to the admin-panel and i try to show only one order, I get an error http://localhost/admin/orders/1
=> BadMethodCallException Method App\Http\Controllers\Voyager\OrdersController::getRelationships does not exist.
can someone help?
Same problem
For me aswell
This problem also me!
This is bc Voayger has been updated since the release of these videos.
You can insert this code:
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";
}
return Voyager::view($view, compact('dataType', 'dataTypeContent', 'isModelTranslatable', 'isSoftDeleted'));
}
}
And it will work
I get this error: Method App\Http\Controllers\Voyager\OrdersController::eagerLoadRelations does not exist.
This is bc Voayger has been updated since the release of these videos.
You can insert this code:
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"; } return Voyager::view($view, compact('dataType', 'dataTypeContent', 'isModelTranslatable', 'isSoftDeleted')); }
}
And it will work
Added these lines of code:
$order = Order::find($id);
$products = $order->products;
return Voyager::view($view, compact('dataType', 'dataTypeContent', 'isModelTranslatable', 'products'));
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";
}
// updated
$order = Order::find($id);
$products = $order->products;
return Voyager::view($view, compact('dataType', 'dataTypeContent', 'isModelTranslatable', 'products'));
}