Closed mailstreetdevelopment closed 4 years ago
Hello,
We need the code and the data to inspect your problem, and it's not "The package Carbon itself", it's AdminController.php
around line 39
according to your stack trace. I can't guess it.
It's the same for:
A login interface
Carbon does not provide such things. Our library only returns date stuffs. If you're working with other dependencies that can depends on Carbon, provide your composer.json and the exact steps you took to get the error.
Thanks,
For the record: the constant declaration is here: https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/CarbonInterface.php#L531
And CarbonInterface.php should be loaded from your vendor directory via the composer autoload. Check your installation is not corrupted.
Hi Kyle, thanks for replying
This is the AdminController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Reservation;
use App\DayTrip;
use App\InformationRequest;
use Carbon\Carbon;
class AdminController extends Controller
{
public function dashboard(Request $request)
{
$latest_reservation = $this->getRelativeDate(Reservation::max('created_at'));
$latest_information_request = $this->getRelativeDate(InformationRequest::max('created_at'));
$information_requests = InformationRequest::orderBy('created_at', 'desc')->paginate(300);
$day_trips = DayTrip::orderBy('starting_at', 'asc');
if (isset($request->history)) {
$day_trips->whereDate('starting_at', '<', date('Y-m-d'));
} else {
$day_trips->whereDate('starting_at', '>=', date('Y-m-d'));
}
$day_trips = $day_trips->get();
return view('admin.dashboard', [
'latest_reservation' => $latest_reservation,
'latest_information_request' => $latest_information_request,
'day_trips' => $day_trips,
'history' => $request->history,
'information_requests' => $information_requests
]);
}
public function getRelativeDate($date_string)
{
Carbon::setLocale('nl');
return Carbon::parse($date_string)->diffForHumans();
}
}
With 'A login interface' I mean the first page of the application when you'd navigate to the URL. Im getting a 500 error and the logs give me the error I posted in the OP.
Composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"maatwebsite/excel": "^3.1",
"propaganistas/laravel-fakeid": "^4.0",
"wildbit/swiftmailer-postmark": "^3.0"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}
I installed a 5.8 laravel app, then modified the composer.json to use yours. Then ran the part of code which implies Carbon:
public function getRelativeDate($date_string)
{
Carbon::setLocale('nl');
return Carbon::parse($date_string)->diffForHumans();
}
Using a valid date as $date_string
it worked well.
Did you check your installation as I suggested? e.g. Checking that /nesbot/carbon/src/Carbon/CarbonInterface.php is present inside your vendor and check that it was well installed in vendor/composer/autoload_classmap.php. If one or the other is missing, it means the composer installation failed and you should run composer install
again to fix it.
Side note: Carbon::setLocale
is not recommended in this case, you should either change globally the locale of your Laravel app (in config/app.php), or just localize the single date you handle:
public function getRelativeDate($date_string)
{
return Carbon::parse($date_string)->locale('nl')->diffForHumans();
}
Hello,
I encountered an issue with the following code: The package Carbon itself
Carbon version: 2.34.2
PHP version: 7.4.6
I expected to get:
But I actually get:
Thanks!