Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question