Do you have fixture_date set as a date in your model?
See: https://laravel.com/docs/5.3/eloquent-mutators#date-mutators
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to make a show page for a zone which will display a list of fixtures.
class UserZoneController extends Controller { public function show($id) { $zone = Zone::findOrFail($id); $fixtures = $zone->fixtures; $fixtures = $fixtures->sortBy('fixture_date');
return view('zone.show')->withZone($zone)->withFixtures($fixtures);
}
}
The above code works so depending on which zone id i use teh show page will display a list of fixtured in date order.
I am now trying to make a $nextFixture variable psode code is $nextFixture = $fixtures->where('fixture_date', '>', now) and get the first one.
I have tried varitions of
public function show($id) { $zone = Zone::findOrFail($id); $fixtures = $zone->fixtures; $fixtures = $fixtures->sortBy('fixture_date');
$next = $fixtures->where('fixture_date', '>', Carbon::today()->toDateString()); // returns null
$next = $fixtures->where('fixture_date', '<', Carbon::today()->toDateString()); // returns null
$next = $fixtures->where('fixture_date', '>', Carbon::today()->toDateString()); // returns null
$next = $fixtures->where('fixture_date', '<', Carbon::today()->toDateString()); // returns nul
dd($next);
return view('zone.show')->withZone($zone)->withFixtures($fixtures);
}
a dd($fixtures) returns ollection {#234 ▼ #items: array:3 [▼ 0 => Fixture {#243 ▼ #fillable: array:8 [▶] #dates: array:1 [▶] #connection: null #table: null #primaryKey: "id" #keyType: "int" #perPage: 15 +incrementing: true +timestamps: true #attributes: array:11 [▼ "id" => "1" "zone_id" => "1" "club_id" => "6" "fixture_date" => "2016-12-29 00:00:00" "fixture_time" => "7PM" "start_sheet_skeleton" => null "start_sheet_official" => null "team_overall" => null "person_overall" => null "created_at" => "2016-12-27 18:24:17" "updated_at" => "2016-12-29 08:30:32" ] #original: array:11 [▶] #relations: [] #hidden: [] #visible: [] #appends: [] #guarded: array:1 [▶] #dateFormat: null #casts: [] #touches: [] #observables: [] #with: [] #morphClass: null +exists: true +wasRecentlyCreated: false } 1 => Fixture {#244 ▶} 2 => Fixture {#245 ▶} ] }
Any ideas?
No data back att all changing from > to < $next = $fixtures->where('fixture_date', '>', Carbon::now()); // returns nothing $next = $fixtures->where('fixture_date', '<', Carbon::now());// returns nothing
I have had to do it like this
$zone = Zone::findOrFail($id);
$fixtures = $zone->fixtures;
$fixtures = $fixtures->sortBy('fixture_date');
// $next = $fixtures->where('fixture_date', '>', Carbon::now());
$next = $fixtures->filter(function ($fixture) {
return $fixture['fixture_date'] > Carbon::now();
});
$next = $next->first();
return view('zone.show')->withZone($zone)->withFixtures($fixtures)->withNext($next);
Please or to participate in this conversation.