Laravel ရဲ့ application structure က application အကြီးဘဲဖြစ်ဖြစ် အသေးဘဲဖြစ်ဖြစ်လွယ်လွယ်ကူကူစနိုင်ဖို့ရည်ရွယ်ထားတာပါ။ သင့် application ကိုသင့်စိတ်ကြိုက် organize လုပ်ချင်သလိုလုပ်လို့ရပါတယ်။ Composer ကနေ Class တွေကို autoload နိုင်သမျှတော့ Laravel မှာ ဘယ် class တွေကဘယ်မှာဘဲရှိရမယ်ဆိုတာမျို့းသတ်မှတ်မထားပါဘူး။
Laravel ကိုအခုမှစတင်မယ့်သူတွေအတွက် Laravel မှာ model
directory မရှိတာ နည်းနည်းရှုပ်ထွေးစေနိုင်ပါတယ်။ သို့သော်လည်း အဲ့လို directory မရှိတာကတမင်သက်သက်လုပ်ထားတာပါ။ "models" ဆိုတဲ့စကားလုံရဲ့ အဓိပါယ်အများကြီးရှိတဲ့အတွက် လူတောတော်များများကို စဝေစဝါဖြစ်စေပါတယ်။ တစ်ချို့ developers တွေက application ရဲ့ "models" ကို business logic အကုန်အဲ့မှာရှိရမယ်ဆိုပြီးရည်ညွှန်းကြပြီးတော့ တစ်ချို့ကကျတော့ relational database တွေရဲ့ အပြန်အလှန်ပြု interact လုပ်ပေးတြ့ class တွေလို့ရည်ညွှန်းကြပါတယ်။
အဲ့ဒီအတွက်ကြောင့် Developer တွေကိုကိုယ်ကြိုက်တဲ့နေရာမှာထားထားနိုင်အောင်လို့ Eloquent models တွေကို app
directory ထဲမှာ default အနေဖြင့်ထားထားတာပါ။
app
directory ကတော့သင်မျှော်မှန်းထားတဲ့အတိုင်းဘဲ application ရဲ့ core code တွေပါဝင်ပါတယ်။ ကျွန်တော်တို့အဲ့ဒီ့ directory ကိုခဏနေကြလျှင် explore လုပ်မှာပါ သို့သော်လည်း သင့် application ရဲ့ classes တွေအကုန်လုံးကအဲ့ဒီ့ directory ထဲမှာရှိမှာဖြစ်ပါတယ်။
bootstrap
directory ထဲမှာ app.php
file ရှိနေမှာပါ။ အဲ့ဒီ့ app.php
file က framework ကို bootstrap လုပ်ပေးထားတာပါ။ bootatrap direcotry ထဲမှာ cache
directory တစ်ခုလည်းပါဝင်မှာဖြစ်ပြီးတော့ အဲ့ဒီ့ folder ထဲမှာ framework ကနေ performance optimization အတွက် generate လုပ်ပေးထားတဲ့ route နှင့် services cache files တွေရှိမှာဖြစ်ပါတယ်။
config
directory ကတော့သူ့အဓိပါယ်အတိုင်း သင့် application ရဲ့ configuration files တွေရှိမှာဖြစ်ပါတယ်။ အဲ့ထဲက files တွေကိုဖတ်ကြည့်ပြီးတော့ configuration ကရရှိချင်တဲ့ရွေးချယ်စရာ configuration options တွေနှင့်ရင်းနှီးကျွမ်းဝင်အောင်လုပ်သင့်ပါတယ်။
database
directory ကတော့သင့် application ရဲ့ database migraation ၊ model factories နှင့် seeds တွေပါဝင်မှာဖြစ်ပါတယ်။ တကယ်လို့သင်က SQLite database သုံးရင်ဒီ folder ထဲမှာ SQLite database ထားနိုင်ပါတယ်။
public
directory ထဲမှာတော့ application စီလာသမျှ request တွေကိုလက်ခံပြီး autoload configure လုပ်ထားတဲ့ index.php
file ရှိမှာဖြစ်ပါတယ်။ ဒီ public
folder ထဲမှာတော့ သင့် application အတွက်လိုအပ်တဲ့ ဓာတ်ပုံထားတဲ့ folder၊ Javascriot နှင့် CSS ထားရှိတဲ့ folder တွေပါဝင်မှာဖြစ်ပါတယ်။
resoruces
directory ထဲမှာတော့ views files တွေနှင့် compile မလုပ်ရသေးတဲ့ LESS၊ SASS နှင့် JavaScript တွေရှိမှာဖြစ်ပါတယ်။ ဒီ directory ထဲမှာသင့်ရဲ့ languages files တွေအတွက် folder လည်းတည်ရှိမှာဖြစ်ပါတယ်။
routes
directory ထဲမှာတော့သင့် application အတွက် route definitions တွေရှိမှာဖြစ်ပါတယ်။ Default အနေဖြင့် web.php
၊ api.php
၊ console.php
နှင့် channels.php
routes တွေရှိမှာဖြစ်ပါတယ်။
web.php
file မှာတော့ RouteServiceProvider
မှာထားရှိတဲ့ web
midddleware group ထဲမှာရှိတဲ့ routes တွေပါဝင်မှာဖြစ်ပါတယ်၊ အဲ့ routes တွေက session state၊ CSRF protection နှင့် cookie encryption တွေထောက်ပံ့ပေးထားပါတယ်။ သင့် application က stateless၊ RESTful API တွေမပါဝင်ဘူးဆိုလျှင်တော့ သင့် route files တွေတော်တော်များများကို web.php
file မှာသတ်မှတ်ရပါလိမ့်မယ်။
api.php
file မှာတော့ RouteServiceProvider
မှာထားရှိတဲ့ api
middleware group ထဲမှာရှိတဲ့ routes တွေပါဝင်မှာဖြစ်ပါတယ်။ အဲ့ api
middleware က rate limiting လုပ်လို့ရပါတယ်။ နောက်ဒီထဲမှာရှိတဲ့ rotues တွေက stateless အတွက်ရည်ရွယ်တာဖြစ်တဲ့အတွက် ဒီ routes တွေဆီလာတဲ့ application တွေက token authentication ကိုအသုံးပြုဖို့ရည်ရွယ်တာဖြစ်လို့ session state အသုံးပြုခွင့်ရှိမှာမဟုတ်ပါဘူး။
console.php
file ကတော့သင့်ရဲ့ Clousre base console commands တွေကိုသတ်မှတ်ဖို့နေရာဘဲဖြစ်ပါတယ်။ Closure တစ်ခုချင်းစီက command instance တစ်ခုချင်းစီရဲ့ IO methods တွေနှင့်လွယ်ကူစွာ interacte လုပ်ဖို့ရာအတွက် bound လုပ်ထားတာပါ။ သို့သော်လည်း ဒီ file မှာ HTTP routes တွေ define မလုပ်ပါဘူး၊ သင့် application ရဲ့ console base entry points (routes) တွေကိုဘဲသတ်မှတ်တာပါ။
channels.php
file ကတော့သင့် application အထောက်အပံ့ပေးတဲ့ event broadcasting channels တွေကို register လုပ်ဖို့ရာအတွက်ဖြစ်ပါတယ်။
storage
directory မှာတော့ compiled လုပ်ထားတဲ့ Blade tempates တွေ၊ file အခြေခံ sessions တွေ၊ cache fiels တွေနှင့် တစ်ခြား framework ကလို generate လုပ်လိုက်တဲ့ file တွေပါဝင်မှာဖြစ်ပါတယ်။ ဒီ directory ထဲမှာ app
၊ framework
နှင့် logs
ဆိုတဲ့ directory တွေပါဝင်မှာဖြစ်ပါတယ်။ app
directory ထဲမှာ သင့် application မှ generate လုပ်လိုက်တဲ့ file အားလုံးကို သိမ်းဆည်းဖို့ရာအတွက်အသုံးပြုပါလိမ့်မယ်။ framework
directory က framework က generate လုပ်လိုက်တဲ့ fiels တွေနှင့် caches တွေကို store ထားမှာဖြစ်ပါတယ်။ နောက်ဆုံး logs
directory ကတော့ application ရဲ့ log fiels တွေပါဝင်မှာဖြစ်ပါတယ်။
storage/app/public
directory ကတော့ user generate လုပ်လိုက်တဲ့ file တွေဖြစ်တဲ့ profile avatar လိုမျိုးတွေသိမ်းဖို့အတွက်သုံးတာဖြစ်ပြီးတော့ publicly အသုံးပြုနိုင်ပါတယ်။ သင့်အနေဖြင့် အခုလက်ရှိ directory ကနေ public/storage
ကို point လုပ်တဲ့ symbolic link တစ်ခု create လုပ်သင့်ပါတယ်။ အဲ့ဒါကို php artisan storage:link
command ကိုအသုံးပြုပြီး create လုပ်နိုင်ပါတယ်။
tests
directory ကသင်ရဲ့ automated tests တွေပါဝင်မှာဖြစ်ပါတယ်။ ဥပမာအားဖြင့် PHPUnit ကို အဆင်သင့်ထည့်သွင်းပေးထားပြီးဖြစ်ပါတယ်။ Test class တိုင်းက Test
ဆိုတဲ့အဆုံးသတ်ပါဝင်ရမှာဖြစ်ပါတယ်။ သင့် tests တွေကို phpunit
သို့မဟုတ် php vendor/bin/phpunit
command တွေနှင့် run နိုင်မှာဖြစ်ပါတယ်။
vendor
directory ကတော့ Composer ရဲ့ dependencies တွေပါဝင်မှာဖြစ်ပါတယ်။
သင့် application ရဲ့ majority က app
directory တည်ရှိမှာဖြစ်ပါတယ်။ ပုံမှန်အားဖြင့် ဒီ directory က App
namespace အောက်မှာရှိမှာဖြစ်ပြီးတော့ Composer ကိုအသုံးပြုပြီး PSR-4 autoloading standard ကိုအသုံးပြုပြီး autoload လုပ်ထားမှာဖြစ်ပါတယ်။
app
directory ထဲမှာအခြားများစွာသော directories တွေဖြစ်တဲ့ Console
၊ Http
နှင့် Providers
တွေပါဝင်မှာဖြစ်ပါတယ်။ Console
နှင့် Http
directory တွေက သင့် application ကိုထောက်ပံ့ပေးတဲ့ core application လို့ယူဆလိုက်ပါ။ HTTP protocol နှင့် CLI နှစ်ခုစလုံးကသင့် application နှင့်ပါတ်သတ်ဖို့ mechanisms လုပ်ထားတာဖြစ်ပြီးတော့ application logic တွေပါဝင်မှာမဟုတ်ပါဘူး။ တစ်နည်းပြောရရင်တော့ ဒီနှစ်ခုကသင့် application ရဲ့ command တွေထုတ်ပေးတဲ့နည်းနှစ်နည်းဖြစ်ပါတယ်။ Console
directory က Artisan Commands တွေပါဝင်မှာဖြစ်ပြီးတော့ Http
directory ကတော့ controllers၊ middleware နှင့် requests တွေပါဝင်မှာဖြစ်ပါတယ်။
make
artisan command ကိုသုံးပြီးတော့ class တွေ generate ထုတ်တဲ့အခါမှာ အခြားများစွာသော directory တွေကို app
directiry မှာ generate လုပ်မှာဖြစ်ပါတယ်။ ဥပမာ app/Jobs
directory ကသင် make:job
artisan command ကို excute လုပ်လိုက်မှ app/Jobs
directory တည်ရှိမှာဖြစ်ပါတယ်။
{မှတ်ချက်}
app
directory ထဲမှ class တော်တော်များကို Artisan command အသုံးပြုပြီး generate လုပ်နိုင်ပါတယ်။ ဘယ်လို command တွေရှိလဲဆိုတာသိရအောင်လို့php artisan list make
command ကို terminal မှာ run ကြည့်နိုင်ပါတယ်။
The Broadcasting
directory contains all of the broadcast channel classes for your application. These classes are generated using the make:channel
command. This directory does not exist by default, but will be created for you when you create your first channel. To learn more about channels, check out the documentation on event broadcasting.
The Console
directory contains all of the custom Artisan commands for your application. These commands may be generated using the make:command
command. This directory also houses your console kernel, which is where your custom Artisan commands are registered and your scheduled tasks are defined.
This directory does not exist by default, but will be created for you by the event:generate
and make:event
Artisan commands. The Events
directory, as you might expect, houses event classes. Events may be used to alert other parts of your application that a given action has occurred, providing a great deal of flexibility and decoupling.
The Exceptions
directory contains your application's exception handler and is also a good place to place any exceptions thrown by your application. If you would like to customize how your exceptions are logged or rendered, you should modify the Handler
class in this directory.
The Http
directory contains your controllers, middleware, and form requests. Almost all of the logic to handle requests entering your application will be placed in this directory.
This directory does not exist by default, but will be created for you if you execute the make:job
Artisan command. The Jobs
directory houses the queueable jobs for your application. Jobs may be queued by your application or run synchronously within the current request lifecycle. Jobs that run synchronously during the current request are sometimes referred to as "commands" since they are an implementation of the command pattern.
This directory does not exist by default, but will be created for you if you execute the event:generate
or make:listener
Artisan commands. The Listeners
directory contains the classes that handle your events. Event listeners receive an event instance and perform logic in response to the event being fired. For example, a UserRegistered
event might be handled by a SendWelcomeEmail
listener.
This directory does not exist by default, but will be created for you if you execute the make:mail
Artisan command. The Mail
directory contains all of your classes that represent emails sent by your application. Mail objects allow you to encapsulate all of the logic of building an email in a single, simple class that may be sent using the Mail::send
method.
This directory does not exist by default, but will be created for you if you execute the make:notification
Artisan command. The Notifications
directory contains all of the "transactional" notifications that are sent by your application, such as simple notifications about events that happen within your application. Laravel's notification features abstracts sending notifications over a variety of drivers such as email, Slack, SMS, or stored in a database.
This directory does not exist by default, but will be created for you if you execute the make:policy
Artisan command. The Policies
directory contains the authorization policy classes for your application. Policies are used to determine if a user can perform a given action against a resource. For more information, check out the authorization documentation.
The Providers
directory contains all of the service providers for your application. Service providers bootstrap your application by binding services in the service container, registering events, or performing any other tasks to prepare your application for incoming requests.
In a fresh Laravel application, this directory will already contain several providers. You are free to add your own providers to this directory as needed.
This directory does not exist by default, but will be created for you if you execute the make:rule
Artisan command. The Rules
directory contains the custom validation rule objects for your application. Rules are used to encapsulate complicated validation logic in a simple object. For more information, check out the validation documentation.