Laravel is a php framework following the MVC pattern with minimal requirements which can be quickly setup for development. Laravel can be used for custom website applications. Below is a short tutorial on how to get started with Laravel quickly.
Laravel comes with a CLI called artisan that can be used to create file skeletons, view paths created, and other helpful commands, you can also create your own commands if you need functionality that isn’t available by default.
i.e.
Creating Controllers with Artisan
php artisan make:controller LoginController
As an MVC framework, models are used to interact with the databases. Functions contained in a modal should be CRUD (Create, Read, Update, Delete) functions Laravel supports 4 database types:
- MySQL
- Postgres
- SQLite
- SQL Server
Once the database and access methods have been setup you can begin adding routes, which control your site’s paths and it’s corresponding controller and function.
i.e.
Example Routes
Route::get('blog', 'BlogController@index');
Route::get('blog/{id}', 'BlogController@getBlogPost');
Routes for path “blog” using BlogController’s index function, and path “blog/{id}” using BlogController’s getBlogPost function which will take the parameter {id} from the path:
The controller will handle any logic that needs to be done and request data from a model if required. Once all logic is complete the controller can return a view for browsers to view or a JSON response if being used for a REST API.
i.e.
Controller Returns
return view('homePage');
return view('blogPost', ['key' => 'Data']);
return response()->json(['key' => 'Data']);
The view contains mostly HTML, any data passed/shared to the view can be displayed as needed. Templates can be standard PHP files or blade templates.
i.e.
PHP Template Example
<html>
<body>
<h1><?php print_r($key); ?></h1>
</body>
</html>
Blade Template Example
<html>
<body>
<h1>{{$key}}</h1>
</body>
</html>
That’s all for this short quick start tutorial. Hope it helps you get started with Laravel development. We will have more extensive tutorial in the future.