Skip to main content

Posts

Showing posts from April, 2022

What is React?

 React is a javascript library for building fast and interactive user interfaces for the web as well as mobile applications  It is an open-source, reusable component-based front-end library  In a model view controller architecture, React is the 'view' which is responsible for how apps looks and feels. React is created by Jorden walke, Who was a software engineer at facebook.  React divides the UI into multiple components, which makes code easier to debug, and each component has it own property and function.  Why React? Easy creation of dynamic web applications  Performance enhancement  Reusable components  Unidirectional data flow  Small learning curve Can be used for mobile apps Dedicated tools for easy debugging

Laravel Restful Actions

Laravel Restful Actions We often use controllers for list some products, add product, update product or Delete product. Now we are dig into for make easy understand the flow. For all this actions you can categorize the 7 Restful actions.   php artisan help make:controller Controller options

Laravel Tinker

Laravel Tinker Laravel Tinker is a powerful REPL Laravel Tinker is a powerful REPL(read-eval-print loop) for the Laravel framework. Tinker by default installed when you install Laravel. May be if you wrongly removed the tinker, you can also install tinker manually using composer composer require laravel/tinker If you are looking Graphical UI, you can check this  Tinkerwell   Usages of Tinker Tinker allows you to interact with your entire Laravel application on the command line, including your Eloquent models, jobs, events, and more. To enter the Tinker environment, run the tinker Artisan command php artisan tinker Let's do with more examples of running real scenario, as early notes we did the blogs module. Now we can consider the blog module as example here. Running models using tinker Record saved at database At the same time you can call methods, events and controller using tinker Fetch all data using Tinker

Tips of multiple file creation

Tips of multiple file creation Creating all files at a time using commands Till now we created Controller, model and migration files all are in individual. You can also create all at a time for your project. Ex: if you take the help of PHP artisan commands like php artisan help make:model Creating multiple files using commands Laravel if you notice that we have options in image if you notice that we have options in image -a -all will create all files Controller, Model, Migration For suppose you need to build new module for "Products". In this case you can simply run the command like php artisan make:model Products -mc This "m" will create the migration file and "c" will create the controller for Products. In this single command we are created model, controller and migration file.

Create MySQL tables

Create MySQL tables Creating MySQL database tables from Laravel To follow Laravel standards, We should create a table using Laravel artisan commands. It will help to other teammates automatically update database changes just with one command. To create a table use below command. php artisan make:migration create_yourTableName_table It will create a table and you can also check the migrate files in the below path mylaravel\database\migrations\ Let's create sample table name called "posts" php artisan make:migration create_posts_table Creating "posts" Table After run this command, Migration file will be created. you can check the migration folder Migration file Let's add some columns in the posts table public function up() { Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('slug'); $table->text('body'); $table->timestamp('pub

Database and Migrations

Database and Migrations You can config Database in the .env file. By default, Laravel has MySQL configuration. For example, I configured my details DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=Laravel_tutorials DB_USERNAME=root DB_PASSWORD= So how it connects the database, In your root folder config/database.php file will read the .env file configuration. Migrations: Migrations are most likely a version control for your database. Advantages You can easily allow your team to modify database schema and share to everyone in the application No headache to add a new column in the database manually. This migration will help all teammates into one path. Now check with artisan command php artisan migrate php artisan migrate This command will create basic users,password_resets and migrations tables. Here migrations table will track of all migrates You can undo previous migration using rollback command php artisan migrate:r

Database connection in Laravel

Database connection in Laravel Database connection establishing and getting data from DB In these notes, you can understand establishing a DB connection and retrieving data from DB. Last previous notes, we made blog post data by hard coding, now fetching data from MySQL database. Here I have created a MySQL database and table for blogs. Now I am going to add MySQL database configuration in Laravel. As we discussed on early notes we should config DB in .ENV file DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=mylaravel DB_USERNAME=root DB_PASSWORD= After this setup, I need to write a method in my controller to fetch data from DB. Example 1 Getting data from DB, This is simple getting data from DB. I used use DB; class and I written direct query. <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class BlogController extends Controller { /* Below as example of getting data from DB */ public function blog_db_example($slug)

Laravel Environment Configuration

Laravel Environment Configuration Common configuration file  By default Laravel save all configuration in .env file. this file defines many common environment variables.  For example: DB config, Production/Development mode, time zone and Debug etc. APP_NAME=Laravel APP_ENV=local APP_KEY=base64:HAv9LHwnZq0QAky7D7l5yy7VJQXyn5mmM8NEcGHYBl4= APP_DEBUG=true APP_URL=http://localhost LOG_CHANNEL=stack LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 MEMCACHED_HOST=127.0.0.1 REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET= PUSHER_APP_ID= PUSHER_APP_KEY= PUSHE

Laravel controllers

Laravel controllers A quick setup of Laravel controllers As we discussed previous articles, Laravel controllers file located at app\Http\Controllers\YourController.php To make a controller To create a controller we usually copy and paste the controller or write the manual code. But in Laravel you can simple run the artisan command to make a new controller file. For example here to make the controller php artisan make:controller YourControllerName

Sending data from routes to views

Sending data from routes to views for a quick understanding of routes Like I said, all the examples will quickly recall what you understood on Laravel. These examples are very basic and I have also provided the correspond pictures. Laravel routes file located at routes\web.php Sending simple string from route to URL.  // Example of sending simple string to views Route::get('/string_example', function () { return "Siddhu first laravel application"; }); The image shows the output Laravel simple string sending to URL from routes At the same time send basic array // Example of sending array data to views Route::get('/array_example', function () { return ["Laravel","PHP","MySQL"]; }); Laravel simple array sending to URL from routes sending simple array to URL. you can notice here, Laravel by default converting array to JSON format.  // Example of sending array data to views Route::get('/json_example', functio

Laravel all artisan commands and uses

Laravel all artisan commands and uses  Laravel commands Have you all know, Laravel run on mostly PHP artisan commands. here I'm going to provide a quick image that show all artisan commands on Laravel.  If do you want to check all Laravel commands, Just run the command on your CMD php artisan You will get all the commands 

Laravel default folders structure and settings

Laravel default folders structure and settings  For a quick application setup Controllers: All controller files are located at app\Http\Controllers\YourController.php Views: All view files are located at resources\views\yourview.blade.php Models: All model files are located at app\Models\yourmodel.php Database Config: Database configuration modify at .env file.

Installation steps Laravel on windows

Simple installation steps on windows Step 1: Install composer on your local machine Step 2: You can install Laravel project by using Composer directly (follow below commands on CMD) composer create-project laravel/laravel project_name cd project_name php artisan serve 1st command will install all Laravel files for your project and  2nd select the project folder and 3rd command will start the server.

Why I choose Laravel?

  Laravel framework provides a structure for creating amazing web applications from starting point. It provides powerful features such as database, dependency injection, Realtime events, queues and scheduled jobs, unit and integration testing. Laravel is best platform to build modern full-stack web applications. Huge community and step-by-step guidance with  video tutorial  support like Laracast.  And finally, Laravel framework grow with you. Whether you are new to PHP or have lot of experience.  Note:  I have written this notes for experience developers for quick setup and directly go to direct point. Instead of explaining in theory. If you are new to Laravel, Kindly follow the Laravel  official site . 

Why Laravel? What are the advantages? How popular is it?

Why Laravel? What are the advantages? How popular is it? Have you getting tired to do tasks like CRUD, sessions, cache, authentication, Routing etc. Then Its time to move Laravel, Why Laravel?     - A single command will finish all the tasks. Such as CRUD, authentication, routing, sessions, and caching.     - A single step migration without data loss     - Automation of Testing Work     - Configuration Error and Exception Handling     - Simple Mail Integration     - Great documentation     - Beautiful code     - A great tutorial and support for beginners such as Laracasts         If you compare Laravel framework popularity with other framework works over the last 5 years.