হ্যালো লারাভেল ৫ । ৪
- Installation
- লারাভেল আড্ডা
- প্রধান কাঠামো বিন্যাস
- থিম / ফ্রন্ট এণ্ড সেটআপ
- ডাটাবেস আলাপ - (Database)
- রিলেশনশিপ
- কন্ট্রোলার - Controller
- রাউটিং - Routing
- কালেকশনস - Collections
- ইলোকোয়েন্ট ও আর এম (Eloquent ORM)
- Eloquent Model
- ফাইল সিস্টেম / স্টোরেজ
- লারাভেল ডাস্ক - Laravel Dusk
- ভ্যালিডেশনস (Validations)
- নেমস্পেস - Namespace
- MVC
ফাইল সিস্টেম / স্টোরেজ
পরিচিতি
ফাইল বলতে মূলত ছবি , ভিডিও , পি ডি এফ এসব বুজায় । যেকোনো সাইট আ এসব থাকে । ফাইল গুলো স্টোরেজ এ থাকে , সেতা হতে পারে লোকাল
, অ্যামাজন এর S3
, Rackspace
, Dropbox
।
কনফিগারেশন
ফাইল সিস্টেম/ স্টোরেজ কনফিগারেশন পাওয়া যাবে config/filesystems.php
এখানে । যেটা দেখতে এরকম ।
|
default
হিসেবে local
- disks
থাকে । disks
পরিবর্তন করে স্টোরেজ করবেন কোথায় ,সেটা ফিক্সড করতে পারবেন ।
লোকাল ড্রাইভার
লোকাল ড্রাইভার কে ফাইল সিস্টেম হিসেবে ব্যবহার করতে চাইলে আপানকে প্রথমে যা করতে হবে ।
|
|
|
Composer Packages:
- Amazon S3:
league/flysystem-aws-s3-v3 ~1.0
- Rackspace:
league/flysystem-rackspace ~1.0
|
Custom Filesystems ()
Dropbox Filesystem
Let’s dive into a simple example where a render
function would be practical. Say you want to generate anchored headings:
|
For the HTML above, you decide you want this component interface:
|
When you get started with a component that just generates a heading based on the level
prop, you quickly arrive at this:
|
|
That template doesn’t feel great. It’s not only verbose, but we’re duplicating <slot></slot>
for every heading level and will have to do the same when we add the anchor element. The whole thing is also wrapped in a useless div
because components must contain exactly one root node.
While templates work great for most components, it’s clear that this isn’t one of them. So let’s try rewriting it with a render
function:
|
Much simpler! Sort of. The code is shorter, but also requires greater familiarity with Vue instance properties. In this case, you have to know that when you pass children without a slot
attribute into a component, like the Hello world!
inside of anchored-heading
, those children are stored on the component instance at $slots.default
. If you haven’t already, it’s recommended to read through the instance properties API before diving into render functions.
createElement
Arguments
The second thing you’ll have to become familiar with is how to use template features in the createElement
function. Here are the arguments that createElement
accepts:
|
The Data Object In-Depth
One thing to note: similar to how v-bind:class
and v-bind:style
have special treatment in templates, they have their own top-level fields in VNode data objects. This object also allows you to bind normal HTML attributes as well as DOM properties such as innerHTML
(this would replace the v-html
directive):
|
Complete Example
With this knowledge, we can now finish the component we started:
|
Constraints
VNodes Must Be Unique
All VNodes in the component tree must be unique. That means the following render function is invalid:
|
If you really want to duplicate the same element/component many times, you can do so with a factory function. For example, the following render function is a perfectly valid way of rendering 20 identical paragraphs:
|
Replacing Template Features with Plain JavaScript
v-if
and v-for
Wherever something can be easily accomplished in plain JavaScript, Vue render functions do not provide a proprietary alternative. For example, in a template using v-if
and v-for
:
|
This could be rewritten with JavaScript’s if
/else
and map
in a render function:
|
v-model
There is no direct v-model
counterpart in render functions - you will have to implement the logic yourself:
|
This is the cost of going lower-level, but it also gives you much more control over the interaction details compared to v-model
.
Event & Key Modifiers
For the .capture
and .once
event modifiers, Vue offers prefixes that can be used with on
:
Modifier(s) | Prefix |
---|---|
.capture |
! |
.once |
~ |
.capture.once or.once.capture |
~! |
For example:
|
For all other event and key modifiers, no proprietary prefix is necessary, because you can simply use event methods in the handler:
Modifier(s) | Equivalent in Handler |
---|---|
.stop |
event.stopPropagation() |
.prevent |
event.preventDefault() |
.self |
if (event.target !== event.currentTarget) return |
Keys:.enter , .13 |
if (event.keyCode !== 13) return (change 13 to another key code for other key modifiers) |
Modifiers Keys:.ctrl , .alt , .shift , .meta |
if (!event.ctrlKey) return (change ctrlKey to altKey , shiftKey , or metaKey , respectively) |
Here’s an example with all of these modifiers used together:
|
Slots
You can access static slot contents as Arrays of VNodes from this.$slots
:
|
And access scoped slots as functions that return VNodes from this.$scopedSlots
:
|
To pass scoped slots to a child component using render functions, use the scopedSlots
field in VNode data:
|
JSX
If you’re writing a lot of render
functions, it might feel painful to write something like this:
|
Especially when the template version is so simple in comparison:
|
That’s why there’s a Babel plugin to use JSX with Vue, getting us back to a syntax that’s closer to templates:
|
Aliasing createElement
to h
is a common convention you’ll see in the Vue ecosystem and is actually required for JSX. If h
is not available in the scope, your app will throw an error.
For more on how JSX maps to JavaScript, see the usage docs.
Functional Components
The anchored heading component we created earlier is relatively simple. It doesn’t manage any state, watch any state passed to it, and it has no lifecycle methods. Really, it’s just a function with some props.
In cases like this, we can mark components as functional
, which means that they’re stateless (no data
) and instanceless (no this
context). A functional component looks like this:
|
Everything the component needs is passed through context
, which is an object containing:
props
: An object of the provided propschildren
: An array of the VNode childrenslots
: A function returning a slots objectdata
: The entire data object passed to the componentparent
: A reference to the parent component
After adding functional: true
, updating the render function of our anchored heading component would simply require adding the context
argument, updating this.$slots.default
to context.children
, then updating this.level
to context.props.level
.
Since functional components are just functions, they’re much cheaper to render. However, this also mean that functional components don’t show up in VueJS Chrome dev tools component tree.
They’re also very useful as wrapper components. For example, when you need to:
- Programmatically choose one of several other components to delegate to
- Manipulate children, props, or data before passing them on to a child component
Here’s an example of a smart-list
component that delegates to more specific components, depending on the props passed to it:
|
slots()
vs children
You may wonder why we need both slots()
and children
. Wouldn’t slots().default
be the same as children
? In some cases, yes - but what if you have a functional component with the following children?
|
For this component, children
will give you both paragraphs, slots().default
will give you only the second, and slots().foo
will give you only the first. Having both children
and slots()
therefore allows you to choose whether this component knows about a slot system or perhaps delegates that responsibility to another component by simply passing along children
.
Template Compilation
You may be interested to know that Vue’s templates actually compile to render functions. This is an implementation detail you usually don’t need to know about, but if you’d like to see how specific template features are compiled, you may find it interesting. Below is a little demo using Vue.compile
to live-compile a template string:
{{ result.render }}
_m({{ index }}): {{ fn }}
{{ result.staticRenderFns }}
{{ result }}