Reputation: 58810
I recently run sudo composer update
Now on one of my pages, I kept getting
I did use
$now = Carbon\Carbon::now('America/New_York');
in line 792
on my Helper.php
My Helper.php located at app/Helper.php
How do I prevent this ?
This is what I have in my aliases
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
'Input' => Illuminate\Support\Facades\Input::class,
'Inspiring' => Illuminate\Foundation\Inspiring::class,
'Lang' => Illuminate\Support\Facades\Lang::class,
'Log' => Illuminate\Support\Facades\Log::class,
'Mail' => Illuminate\Support\Facades\Mail::class,
'Password' => Illuminate\Support\Facades\Password::class,
'Queue' => Illuminate\Support\Facades\Queue::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
/*
* Extra Alias ...
*/
'Form' => 'Illuminate\Html\FormFacade',
'Html' => 'Illuminate\Html\HtmlFacade',
/*
* Custom ...
*/
'VSE' => App\VSE::class,
'Helper' => App\Helper::class,
'DateHelper' => App\Helpers\DateHelper::class,
'DD' => App\Helpers\DD::class,
'Facebook' => SammyK\LaravelFacebookSdk\FacebookFacade::class,
],
Upvotes: 8
Views: 33971
Reputation: 518
In the helper.php
file, use Carbon
class like this.
use Carbon\Carbon;
Upvotes: 0
Reputation: 6351
If You are Using larave 5.7.*
use Illuminate\Support\Carbon;
In Model or Controller Where You want
Upvotes: 0
Reputation: 1
//laravel 5.6
//In your Controller
use Carbon\Carbon;
//ex. function
public function store(Request $request)
{
$borrow = new Borrow;
$borrow->user_id = Auth::user()->id;
$borrow->book_id = $request->input('book_id');
$borrow->borrowtime = Carbon::today(); //This uses the class Carbon
$borrow->returntime = "-----------";
$borrow->save();
return redirect('student/Categories/Thesis/showtt');
}
Upvotes: 0
Reputation: 21
After going through this, i found a way out, it might help someone there.
In laravel go to app.php, go to aliases and add 'Carbon' => 'Carbon\Carbon'. Then use this in blade to format it e.g.
<span>{{ Carbon::createFromTimeStamp(strtotime($message->created_at))->diffForHumans()}}</span>
.Done.
Upvotes: 2
Reputation: 12368
In the context of the helpers file, I believe Carbon\Carbon
= App\Carbon\Carbon
Whereas \Carbon\Carbon
would be pulling in what you want!
Using the \
at the beginning refers to a sort of global namespace.
Upvotes: 20