Laravel 5 tutorial php framework for beginner : how to create controllers and laravel controller validation, laravel controller testing in laravel.
Laravel 5 Tutorial - Model View Controller in MVC PHP Framework that the 'C' letter mean a Controller. In Laravel Php Framework we can create Controllers for easy using the 'Artisan' CLI (Command Line Interface).
Please Read :
Default constructor will be place at app\Http\Controllers. You can see that basic source code of the 'homeController.php'.
The Controllers is called from routes.php that placed at app\Http\routes.php.
Here's simple syntax from the routes.php file :
if users enter the base Url "/" that will call the "homeController.php" at the "index" method.
If success, You can see loginController.php at app/Http/Controller/loginController.php with some basic coding already written for you.
loginController.php
You can add some functions into loginController.php like this examples
The array will send to "login.blade.php" in resources\views\ folder, just create the login.blade.php and fatch the array.
login.blade.php
routes.php
Now, you can execute "http://localhost:8080/login" url in your browser, and you'll get the array data that send to login.blade.php
For more about Basic Controllers in laravel, please subscribe us and enjoy coding.
see you next lessons...
Please Read :
Default constructor will be place at app\Http\Controllers. You can see that basic source code of the 'homeController.php'.
The Controllers is called from routes.php that placed at app\Http\routes.php.
Here's simple syntax from the routes.php file :
Route::get('/', 'homeController@index');
if users enter the base Url "/" that will call the "homeController.php" at the "index" method.
How to Create Controller from Artisan CLI?
To create controller using Artisan CLI in laravel just follow this method.Example :php artisan make:controller [options] [--] <name>
c:\xampp\htdocs\laravel>php artisan make:controller loginController
If success, You can see loginController.php at app/Http/Controller/loginController.php with some basic coding already written for you.
loginController.php
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequests;
class loginController extends Controller
{
//
}
You can add some functions into loginController.php like this examples
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequests;
class loginController extends Controller
{
public function index() {
$data = ['harison','Harison Matondang','www.hc-kr.com','Indonesia','123456'];
return view('login')->with('logindata',$data);
}
}
The array will send to "login.blade.php" in resources\views\ folder, just create the login.blade.php and fatch the array.
login.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login Data</title>
</head>
<body>
<h2>There is the login data :</h2>
@if(count($logindata))
<ul>
@foreach($logindata as $login)
<li> {{ $login }} </li>
@endforeach
</ul>
@endif
</body>
</html>
routes.php
Route::get('/login', 'loginController@index');
Now, you can execute "http://localhost:8080/login" url in your browser, and you'll get the array data that send to login.blade.php
see you next lessons...
COMMENTS