Laravel select v Controller vysvetlenie

Laravel select v Controller vysvetlenie
« kdy: 29. 05. 2019, 00:42:28 »
Nie je mi jasne ako funguje select v Laravel resp. neviem ako ho spravne pouzit alebo je vela hodin. Ale k veci.
V WindrController je nieco taketo
Kód: [Vybrat]
public function create(Request $request, User $user, CoinpaymentsPaymentService $coinpaymentsPaymentService) {
     $checkstatuswindraw = $user->account->related(Withdrawal::class)->where('status', '0')->first();
         
        if (!empty($checkstatuswindraw))
           $checkstatuswindraw = 'noepty';
                       
        if ($user->id != $request->user()->id)
            abort(404);
   
           
        return view('payments::frontend.pages.withdrawals.create', [
            'account'       => $user->account,
            'enablewindraw' => $checkstatuswindraw,
            'currencies'    => $coinpaymentsPaymentService->getAcceptedCurrencies()
           
        ]);
    }

mna zaujima tento riadok
 $checkstatuswindraw = $user->account->related(Withdrawal::class)->where('status', '0')->first();
konkretnejsie related. Ako to spravit tak aby te related nebol Withdrawal::class ale napriklad table('deposit')?
Na co presne pouzijem ten related?
Ako by som inak v Laravel napisal select * from Withdrawal where status = 0 and  where user = 'admin' ? Ked napisem
$checkstatuswindraw = DB::table('Withdrawal')->where('status', '0')->where('user', 'admin')->first(); hadze mi to 500.
preco?
« Poslední změna: 29. 05. 2019, 00:47:48 od Wangarad »


robin martinez

  • *****
  • 1 138
  • Have you hugged your toilet today?
    • Zobrazit profil
    • Null Storage
    • E-mail
Re:Laravel select v Controller vysvetlenie
« Odpověď #1 kdy: 29. 05. 2019, 09:16:48 »
Laravel jsem nejakej cas nedelal, ale jde o to, jak si naprogramujes jednotlivy tridy eloquent-u a jednotlivy vazby mezi nima

ale ta druha vec by mohla byt takhle, ne?

Kód: [Vybrat]
$where = [
'name', '=', 'admin',
'status', '=', 0,
];

$checkstatuswindraw = DB::table('Withdrawal')->where($where)->first();

])
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man.

I do Linux, Hardware and spaghetti code in PHP, Python and JavaScript

Re:Laravel select v Controller vysvetlenie
« Odpověď #2 kdy: 31. 05. 2019, 18:50:38 »
Chtelo by to vic info. Kompletni chybovej vypis, struktura tabulky a hlavne co to ma delat. Ale na prvni pohled si nemyslim, ze bude v tabulce vyberu uzivatel jako string.