I want to return a table and descend from the highest average of runs to the lowest for each player using Laravel 5.4
I have two tables
**Player**: id, Name, Nationality, accepted
**Batting_innings**: Id, runs, player_id
models:
class Player extends Model
{
public function batIngs()
{
return $this->hasMany('App\battingIns','player_id');
}
}
in my controller currently i am using this:
public function index(Request $request)
{
//
$bat = Player::all();
$batsmen =Player::where('accepted', '=', 1)->orderBy($bat->batIngs->avg('runs');
$batsmen=$batsmen->paginate(10);
return view('pages.search')->with('batsmen', $batsmen)
}
I get the error that batIngs isnt found. Any idea how to do this?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sUQoNQ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire