HomeLaravel

Laravel 5 Tutorial : Basic Controllers in laravel

Laravel 5 tutorial php framework for beginner : how to create controllers and laravel controller validation, laravel controller testing in laravel.

Laravel 5.7 Tutorial : Datatables API with Example in Laravel 5.7
Laravel 5.7 is now released! What's New in Laravel 5.7
[SOLVED] Laravel 5.5 Specified key was too long max key length is 767 bytes
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 :
  1. How to Install Laravel 5 on windows Localhost
  2. Basics Routing in Laravel
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.
php artisan make:controller [options] [--] <name>
Example :
c:\xampp\htdocs\laravel>php artisan make:controller loginController
Basic Controllers in laravel

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
Basic Controllers in laravel

For more about Basic Controllers in laravel, please subscribe us and enjoy coding.
see you next lessons...

Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


COMMENTS

DISQUS
Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,89,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,6,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Laravel 5 Tutorial : Basic Controllers in laravel
Laravel 5 Tutorial : Basic Controllers in laravel
Laravel 5 tutorial php framework for beginner : how to create controllers and laravel controller validation, laravel controller testing in laravel.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBJE5X58CAPA-qq5IoW7S3AqaMri6mMASkyyNvNqv4sOx439tMXLxe1y9wmNnfu4FUlZUxCdnsIr8_GVoLfOpwOkHiNPr8DI6Uza72uEjeTO9NU3dS8YKHncqnWbUkITtQ1cnrLGqFOyA/s320/controller-basic-laravel5.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBJE5X58CAPA-qq5IoW7S3AqaMri6mMASkyyNvNqv4sOx439tMXLxe1y9wmNnfu4FUlZUxCdnsIr8_GVoLfOpwOkHiNPr8DI6Uza72uEjeTO9NU3dS8YKHncqnWbUkITtQ1cnrLGqFOyA/s72-c/controller-basic-laravel5.png
KODE AJAIB
https://scqq.blogspot.com/2016/08/laravel-5-tutorial-basic-controllers-laravel.html
https://scqq.blogspot.com/
https://scqq.blogspot.com/
https://scqq.blogspot.com/2016/08/laravel-5-tutorial-basic-controllers-laravel.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy