W
W
walkerstech2021-05-06 01:07:33
Laravel
walkerstech, 2021-05-06 01:07:33

Wrong request in model?

Another stupid question, there is an "orders" table, where the history of orders is stored, and the ID of the item that was purchased is stored there. Output as an array.
And it is necessary to implement a query to the second table "items" with the search for item_id from orders.
As a matter of fact, I can’t make a correct request, where each item_id is transmitted separately

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use App\Models\Orders;
use App\Models\Items;

class UserController extends Controller
{
    public function index()
    {
        $user = Auth::user();
        $orders = Orders::where(['user_id' => $user->id, 'order_status' => 1])->get();
        $items = Items::where('item_id', $orders->item_id)->orderBy('created_at', 'desc')->toBase()->get();
            return view('home', compact('user', 'orders', 'items'));
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2021-05-06
@walkerstech

https://laravel.com/docs/8.x/eloquent-relationships

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question