lundi 2 novembre 2020

Laravel | newQuery inside dataTables returning 10 results only from many within the database

Not sure what's wrong here. In my App/dataTables I have something with this method :

public function query(ProductOrder $model)
{   
    return $model->newQuery()->with("product")
        ->where('product_orders.order_id', $this->id)
        ->select('product_orders.*')->orderBy('product_orders.id', 'desc');
}

As you can see i'm pulling things from the product_orders table where product_orders.order_id = the value i pass. There are more than 10 results always within the database, but the result returned is always limited to 10. Can someone please help to understand why ? Does newQuery has any such automatic limit on the number of rows fetched ?



via Chebli Mohamed

Eloquent max value of child's child

I have 3 tables

auctions [id, winner_user_id, title]
bids [id, auction_id, amount, user_id]
users [id, name]

relations

Auction
...
public function winningBidder(){
   return $this->belongsTo('User', 'winner_user_id', 'id');
}
public function bids(){
   return $this->hasMany('Bid');
}
User
...
public function bids(){
   return $this->hasMany('Bid');
}
Bid
...
public function auction(){
   return $this->belongsTo('Auction');
}
public function user(){
   return $this->belongsTo('User');
}

What i am trying to do is the highest bid for the winner

eager load
$auctions = Auction::with('winningBidder.bids')->get();

loads all bids instead of bids of that auction and adding max(amount) to about will give max of all

is it possible to get highest bid of winning user for each auction?



via Chebli Mohamed

dynamic rate limiting in laravel

I want to know if it possible to use a value stored in redis cache or mongodb for dynamic rate limiting using throttle middleware. I tried the way of mentioning limit in user model but either I did that in a wrong way or it is not working.



via Chebli Mohamed

why my cron job is not working in laravel?

in db i have column visit_clear i want it 0 after one day so i used this code in kernal.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected $commands = [
    ];
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('cron:update-user-not-new')->daily();
    }

    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

and in command/UpdateUserNotNew.php

    public function handle()
        {
            $dayAgo = 1; // Days ago
            $dayToCheck = \Carbon\Carbon::now()->subDays($dayAgo)->format('Y-m-d');
            Customer::whereDate('visit_date', '<=', $dayToCheck)
            ->update([
                'visit_clear' => 0
            ]);
        }

i am sheduling commnd like this as u can see cron:update-user-not-new should i use crone:UpdateUserNotNew?



via Chebli Mohamed

How to I can show date in laravel blade from my table in this input field

How to I can show date in laravel blade from my table in this input field

***<div class="form-group">
                <strong>Date:</strong>
                <input type="date" name="date" class="form-control" value="" placeholder="Date">
            </div>***


via Chebli Mohamed

Why in Laravel 5 orderBy desc Query not fetching data

$todos = Todo::orderBy('created_at', 'desc')->get(); return view('todos.index')->with('todos', $todos);



via Chebli Mohamed

dimanche 1 novembre 2020

Pass data from blade to vue and keep parent-child in sync?

I know that in Vue parents should update the children through props and children should update their parents through events.

Assume this is my parent component .vue file:

<template>
<div>
    <my-child-component :category="category"></my-child-component>
</div>
</template>

<script>
export default {
  data: {
     return {
       category: 'Test'
     }
  }
}
</script>

When I update the category data in this component, it will also update the category props in my-child-component.

Now, when I want to use Vue in Laravel, I usually use an inline template and pass the value from the blade directly to my components (as for example also suggested at https://stackoverflow.com/a/49299066/2311074).

So the above example my my-parent-component.blade.php could look like this:

@push('scripts')
   <script src="/app.js"></script>
@endpush

<my-parent-component inline-template>
    <my-child-component :category=""></my-child-component>
</my-parent-component>

But now my-parent-component is not aware about the data of category. Basically only the child knows the category and there is no communication between parent and child about it.

How can I pass the data from blade without breaking the parent and child communication?



via Chebli Mohamed