11/1/19

Controllers in Laravel | Part - 5



Controllers (HTTP->Controllers)
----------------------------------
Controllers are these classes that deal with information coming from database and relating that information this plane and or passing information through to a view or a representation of our application which could be maybe a contact page or a user's page or something like that right. So Controller controls the information that comes from the database going to the view the from of the application. It can also control information coming from the representation form the view and taking it back to the database.

You will learn how to create a controller manually. And we also learn it by using the PHP command-line tool PHP 'artisan'. let me show you how to find more commands and PHP artisans.

open terminal and type the commands (PHP artisan command):

PHP artisan - if you type and look at some of this you could tell what they do. (This deals with databases, this use route, controllers, model..etc) We can make it with PHP artisan.

make controller -
php artisan make:controller --resource PostsController

after creating the controller, the terminal has been printed 'Controller created successfully'.

-------------------------------------------------


special controller:
--------------------------------------------------
A controller with a resource a route (Route:: resource()). this a special static function like Route::get(). That will give us access to automatically two different types of routes. that we can use a controller.

the resource will help us very simply bt creating special routes for us that we can use in the controller.

PHP artisan route: list - this command, you can check what are methods available.

------------------------------------------------------

namespace:
namespace does for function in classes scope does for variables basically it allows us to use the same function name and class name in different parts of the same application without causing any problem. So basically We organize those functions in different parts of our application even though they have the same name. we use a namespace to differentiate the functions. We don't have a collision

use:
use is import that specific class or namespace to this scope right here / to this file.

------------------------------------------------------
Routing Controller

we can create the controller in two way
1. using php artisan command (php artisan)
2. manually create the controller file

No comments:

Post a Comment

About

Hi, I'm Najathi.
I've started entrepreneurial company, Twin Brothers.Inc.
One is self-funded & the other is venture backed. I also send a weekly. where I share relevent, curated links.

Every Week I Publish a short post on writing, publishing, or content of IT Related

Contact Form

Name

Email *

Message *