اذهب إلى المحتوى

السؤال

نشر

لدي مشكلة في تحميل بيانات العلاقة عند فلترة البيانات بناء على ما أدخله المستخدمون. غالبا ما أستخدم with () لتحميل العلاقات ، لكن في هذه الحالة لا يعمل ولا أعرف السبب. هذا هو الكود الخاص بي

public function fotoTrxSearch(Request $request){

    $transaction = Foto::orderByDesc('id'); 
    //i tried something like $transaction = Foto::with('mediaCategory','user')->orderByDesc('id'); but nor working

    if($request->filled('name')){
        $transaction->where('name', 'like', "%{$request->name}%");
    }
    if($request->filled('from') AND $request->filled('to')){
        $transaction->whereBetween('date', [$request->get('from'), $request->get('to')]);
    }
    if($request->filled('price')){
        $transaction->where('price','like', "%{$request->price}%");
    }
    if($request->filled('user_id')){
        $transaction->where('user_id',$request->user_id);
    }
    if($request->filled('media_id')){
        $transaction->where('media_id',$request->media_id);
    }
    if($request->filled('folder')){
        $transaction->where('folder','like', "%{$request->folder}%");
    }

    $transaction = new FotoCollection($transaction->paginate(150)->appends($request->query()));
    //also tried $transaction = new FotoCollection($transaction->with('mediaCategory','user')->paginate(150)->appends($request->query())); not working


    return Inertia::render('Foto/FotoList',[ 'fotos' => $transaction , 'user' => $user , 'mediaCategories' => $mediaCategories]);
   
}

حاولت أن أفعل التالي

$transaction = Foto::with('mediaCategory','user')->orderByDesc('id');enter code here

والتالي ايضا

$transaction = new FotoCollection($transaction->with('mediaCategory','user')->paginate(150)->appends($request->query()));

أرجو مساعدتي

Recommended Posts

  • 0
نشر

استاذي الفاضل

يجب أن تستخدم get في نهاية السطر 

لان الدوال المكتوبة ترجع اوبجكت من ال eleqouent وليس الداتا نفسها

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...