Comments (4)
请学会使用 Laravel Facade,以及仔细看文档哦:https://github.com/overtrue/laravel-shopping-cart#installation
from laravel-shopping-cart.
谢谢,又学到了一些,但是还是有个地方不明白,如果我在控制器中直接使用Cart::add(),这个时候导入的命名空间是use Overtrue\LaravelShoppingCart\Cart; 这个,这个如果用静态方式调用的话会出现错误.除非我不导入命名空间,直接使用\Cart:add()就没有问题.
在app.php 中
也加了.
from laravel-shopping-cart.
额,我都建议你去学一下命名空间了,这里一共有两个类:
use Overtrue\LaravelShoppingCart\Cart;
use Overtrue\LaravelShoppingCart\Facade;
上一个是最后业务使用的类,并非静态,后者 Overtrue\LaravelShoppingCart\Facade
是上一个 Overtrue\LaravelShoppingCart\Cart
类的外观类,静态代理,而在 Laravel 配置 config/app.php
里配置 aliases
:
'Cart' => Overtrue\LaravelShoppingCart\Facade::class,
这行的作用是在根命名空间 \
下创建了别名类 \Cart
指向 \Overtrue\LaravelShoppingCart\Facade
, 所以使用 use Cart
或者 \Cart
都是使用 \Overtrue\LaravelShoppingCart\Facade
。
请分清楚这里的 \Cart
与 \Overtrue\LaravelShoppingCart\Cart
的区别,它俩完全是两个不同的东西,一个是根空间下的 Cart
,另一个是 根空间 下的 Overtrue\LaravelShoppingCart\Cart
, 所以并没有 "除非我不导入命名空间" 这样的说法存在。
类别名:http://php.net/manual/en/function.class-alias.php
命名空间:http://php.net/manual/zh/language.namespaces.php
from laravel-shopping-cart.
哦哦,好的,谢谢啊,基础较差,感谢你的耐心讲解
from laravel-shopping-cart.
Related Issues (14)
- composer 组件开发 HOT 1
- support 5.7? HOT 6
- ShoppingCart::all(); return null HOT 7
- About Specifies the associated model HOT 4
- 类中的fire方法替换dispatch方法
- Update does not work during adding of the same item if quantity is different HOT 2
- composer install error HOT 2
- Eager loading associate model
- How to set cart name dynamically? HOT 1
- Creates duplicate item in the cart list
- Undefined type HOT 1
- 关于监听事件传入参数为空的BUG探讨 HOT 1
- Store in database and edit the order
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-shopping-cart.