php 未找到 Laravel 5 类“App\Carbon\Carbon”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39902831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'App\Carbon\Carbon' not found Laravel 5
提问by cyber8200
I recently runsudo composer update
我最近跑sudo composer update
Now on one of my pages, I kept getting
现在在我的其中一页上,我不断收到
I did use
我确实用过
$now = Carbon\Carbon::now('America/New_York');
$now = Carbon\Carbon::now('America/New_York');
in line 792
on my Helper.php
在792
我的线上Helper.php
My Helper.phplocated at app/Helper.php
我的Helper.php位于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,
],
回答by haakym
In the context of the helpers file, I believe Carbon\Carbon
= App\Carbon\Carbon
在 helpers 文件的上下文中,我相信Carbon\Carbon
=App\Carbon\Carbon
Whereas \Carbon\Carbon
would be pulling in what you want!
而\Carbon\Carbon
将拉入你想要的东西!
Using the \
at the beginning refers to a sort of global namespace.
使用\
之初是指一种全局命名空间的。
回答by Awonusi Olajide
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.
在 Laravel 中转到 app.php,转到别名并添加 'Carbon' => 'Carbon\Carbon'。然后在刀片中使用它来格式化它,例如
<span>{{ Carbon::createFromTimeStamp(strtotime($message->created_at))->diffForHumans()}}</span>
.Done.
。完毕。
回答by pawan kumar
use Carbon\Carbon in AuthserviceProviders
在 AuthserviceProviders 中使用 Carbon\Carbon
回答by Ryan
//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');
}
回答by Manojkiran.A
If You are Using larave 5.7.*
如果您使用的是larave 5.7.*
use Illuminate\Support\Carbon;
In Model or Controller Where You want
在您想要的模型或控制器中
回答by Natvarsinh Parmar - bapu
Use Carbon:
使用碳:
use Carbon\Carbon;
回答by Sheetal Mehra
In the helper.php
file, use Carbon
class like this.
在helper.php
文件中,Carbon
像这样使用类。
use Carbon\Carbon;