FavoriteLoadingAdd to favorites

A Controller or Class in MVC are both just classes.
So… Technically speaking.
It is possible to write all your functionality inside your controllers and completely ditch the classes folder.
But! The purpose of breaking out into separate classes is re-usability.

Controllers :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
namespace App\Http\Controllers;
class MyCustomController extends Controller
{
}
<?php namespace App\Http\Controllers; class MyCustomController extends Controller { }
<?php

namespace App\Http\Controllers;

class MyCustomController extends Controller
{

}

Classes :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
namespace App\Classes\MyCustomClass;
class ClassNameWhateverWhatever
{
}
<?php namespace App\Classes\MyCustomClass; class ClassNameWhateverWhatever { }
<?php

namespace App\Classes\MyCustomClass;

class ClassNameWhateverWhatever
{

}

Why Classes, what is the point?
—————————————————————–
Classes serve as containers for specific purposes.
For example.

You create a class for :
Car

And inside your class you write all your functionality.
A car can have specific functionality.

moveForward()
reverse()
brake()
switchOnLights()

—————————————————————–
Then, you reference your car class inside your contollers.

So something like
car->moveForward();

This design strategy makes your code extremely easy to re-use without having to re-write additional functionality. This is why we seperate everything into a class and then we create another class called a controller class and reference our classes inside the controller classes.

Pin It on Pinterest

Garth Baker
Favorite
Loading
en
af
sq
am
ar
hy
az
eu
be
bn
bs
bg
ca
ceb
ny
zh-CN
zh-TW
co
hr
cs
da
nl
en
eo
et
tl
fi
fr
fy
gl
ka
de
el
gu
ht
ha
haw
iw
hi
hmn
hu
is
ig
id
ga
it
ja
jw
kn
kk
km
ko
ku
ky
lo
la
lv
lt
lb
mk
mg
ms
ml
mt
mi
mr
mn
my
ne
no
ps
fa
pl
pt
pa
ro
ru
sm
gd
sr
st
sn
sd
si
sk
sl
so
es
su
sw
sv
tg
ta
te
th
tr
uk
ur
uz
vi
cy
xh
yi
yo
zu
Share This