Categories
Laravel Programming

Laravel 5.8 Creating a MVC project with CRUD in 5 steps

This Laravel tutorial deals with the Installation, Setup and Basic Laravel MVC usage to open a page with intro to the CRUD operations.

Don’t know how to setup a new Laravel project or you are a 20 year old pro who is too pro to touch the basics? This is the right place to be.  I’ll keep referencing this tutorial whenever Installation is needed in my other Laravel posts.

It is expected that you are familiar with the basics of windows and linux server administration. If you need more help then please use Google. But I will try to avoid the basics to make sure that the goals are achieved without any fuss.

Now I don’t joke around. As per the tradition of this blog, I will make sure that you achieve this goal with the least effort wasted on figuring out wtf is this blog talking about. Let me know in the comments if you find it helpful. So let’s get started!

The 12345 Steps 🙂 :

  1. Setup of new project and running the server to make sure it bites.
  2. Creating a Database (mysql)
  3. Performing Migration to create schema
  4. Controller to repeatedly insert and render a View
  5. Test! and Conclusion

1. Setup and running new project

Lets learn how to install a new Laravel project with running a server on default port 8000.

Before we start, it is important that you should simply follow the official documentation for the latest Laravel Version installation guideline. I don’t want you to look backward when mentioning my blog. 

Source: https://laravel.com/docs/5.8/installation

So create a folder in your drive and open the console in it like so:

Opening the Laravel root project folder in windows command prompt or terminal
Opening the Laravel root project folder in windows command prompt or terminal

Now, lets create a project by running the following command in console:

laravel new codeonion_tutorial 

This creates a “codeonion_tutorial” folder and will start downloading the assets we need.

Creating a new Laravel project
Creating a new Laravel project

After a decade of waiting, the project will be ready. Now let’s make sure that it is running.

  • I go into the codeonion_tutorial project by  cd codeonion_tutorial
  • Start the Server:

php artisan serve

  • Visit the IP address as provided by the console output. Mine by default shows http://localhost:8000
  • So it works. You can now create a database.

2. Creating a Database (mysql)

Lets learn how to create a database in phpmyadmin for a Laravel project. But first, lets enjoy this breathtaking performance by the star of this blog.

Dancing Banana
Dancing Banana

You might be using XAMPP, LAMPP or plain old terminal based mysql server. I don’t care. AS a professional, you must have to know how to create a database. Heck! You must be able to follow this tutorial with using other database engines as well. So help yourself and learn that part as well. Let me know if you want me to make a tutorial about that. Otherwise, just keep following.

I am using Windows and Xampp. Run the Mysql server and open phpmyadmin

Running a Xampp Server for phpmyadmin
Running a Xampp Server for phpmyadmin

Then visit http://localhost/phpmyadmin/

phpmyadmin interface
phpmyadmin interface

Now, let’s create a database. Press New as shown below:

Create a new Database in phpmyadmin
Create a new Database in phpmyadmin

A Create database page will open which is explained below:

Write name of database and press create
Write name of database and press create
  1. Write name of your database to be.
  2. Press Create
  3. Done! (but also note these sub points)
    1. It could
      1. Fail if it violates any rules of database server
      2. It could also fail if your database is not allowed
      3. It could also fail if your Hosting service limits you by number of databases you can make
    2. Now how many bloggers would tell you about these things !! ;D

3. Performing Migration to create schema

Here, lets learn how to perform migrations and database configuration in Laravel.

Nothing is easy nowadays. You have publishers destroying true game developers and companies and then you have web frameworks made confusing by ignorant bloggers. I am all of them combined. So let’s configure our project database for migrations.

  • Our composer installation of the Laravel has already set the .env configuration file in place. But let’s do that manually to exercise the process.
Pointing out the .env configuration file of the Laravel Project
Pointing out the .env configuration file of the Laravel Project
  • Go to the terminal/command line and execute the following command

The .env file will be created and we will now configure it for our database. Open the .env file in the root folder of your newly created project and find the following highlighted database configuration

Editing the .env configuration file in Laravel
Editing the .env configuration file in Laravel

Lets set it to match our database

Laravel default phpmyadmin mysql configuration
Laravel default phpmyadmin mysql configuration

Migrations

First we have to clean the migration files created by composer. Go to the database/migrations/ folder and delete all files.

Now let’s create a migration file. Execute the following command from the root folder of the project.

php artisan make:migration create_messages_table
Creating migration files in Laravel
Creating migration files in Laravel

Now from the root folder, go to database/migrations/ folder and open the latest file which was created. Migration file that was created for me was:

2019_07_14_162743_create_messages_table.php

It has a timestamp along with the name I designated in the filename.

Open the file and lets add commands to create our “messages” table..

Initially, it will contain up and down functions (which handle what happens when we want the executions to be at up or down state in our database server).

Basic Laravel migration file usage
Basic Laravel migration file usage

Lets add the following line after the “id” column line in the up() function

$table->string(‘message’);

Editing the laravel migration file to refer to the table column
Editing the laravel migration file to refer to the table column

Lets run the migration using 

php artisan migrate

Laravel migration process
Laravel migration process

Note that if you screwed up, then you can “undo” the migration using php artisan migrate:rollback but it is not necessary to do now.

At this time, go to phpmyadmin and you will see that our table has been created.

Table updated in phpmyadmin after migration was performed in Laravel
Table updated in phpmyadmin after migration was performed in Laravel

Now, lets make a web page which repeatedly inserts into that table and fetches all and displays into a page. Sweet!

4. Controller to repeatedly insert and render a View

Lets learn how to create a Model, controller, view and route for our Laravel project.

Our database is connected, migrations are up. Now we need to populate the table and then we need to display it on the screen. So lets start without any regular fuss that I am used to deliberately provide to you include this once.

MODEL CREATION

Lets learn how to create a Model for the messages table. This model will be used by the controller.

First, lets create a model by executing this command

php artisan make:model Message

Open the model file at root/app/Message.php and change its content to make sure that it points to the correct table. Add the highlighted line and save it.

Model referring to the database table
Model referring to the database table

Now we can use the model in our controller.

CONTROLLER CREATION

Lets learn how to make a controller for our view. This controller will call out modal to add a random message and fetch all messages.

We need to create a controller. From the root folder, execute this command
php artisan make:controller MessageHandler

Creating a controller in Laravel using command line
Creating a controller in Laravel using command line

This will create a controller file in rootfolder/app/Http/Controllers

Open the root/app/Http/Controllers/MessageHandler.php and change the contents of the controller file as follows:

Laravel controller to insert into table  and get all the records to display in a web page
Laravel controller to insert into table and get all the records to display in a web page

This controller code:

  1. Creates a random message
  2. Saves it to the database in messages table.
  3. Retrieves all the messages
  4. Displays them in separate lines

Now, let’s make a route

ROUTE

Lets learn how to make a route for our controller.’s process_and_display action

Open root/routes/web.php and add this to the bottom of it:

Route::get(‘show_message’, ‘MessageHandler@process_and_display’);

We are now done with the MVC!

5. Test! and Conclusion

So we have done it all. Lets go to the http://localhost:8000/show_message and see what happens after we refresh the page several times.

Successfully showing the tutorial output
Successfully showing the tutorial output
[jetpack_subscription_form show_only_email_and_button=”true” custom_background_button_color=”undefined” custom_text_button_color=”undefined” submit_button_text=”Dancing BananaSubscribe For More” submit_button_classes=”undefined” show_subscribers_total=”true” ]

You should now review the above steps. Go over the project you created and learn what was done in each step.Read documentation and learn more.

Please let me know in the comments about this post and tell me if there is more I can do. We have now learnt about Installation, Setup and Basic Laravel MVC usage to open a page with intro to the CRUD operations .

android autocomplete camera code codeiginter 3 Codeigniter codeigniter 3 computer vision CSS database education files help helpful how how to HTML HybridIgniter installation java knoppix laravel learn libraries linux mobile mvc open opencv OpenCV4Android PHP plugin project responsive review Review – Web Design WYSIWYG SDK solution touchpad tutorial upload Video web design wordpress WYSIWYG

Categories
Android OpenCV Programming

Creating a new OpenCV project in Android Studio

Return to OpenCV for Android Tutorials List

In this tutorial, we will create a new OpenCV project in Android Studio. Since you have everything downloaded already, we are ready to move on. By the end of this tutorial, you will have a new project set up, which you can use to build your projects upon. So lets do some CV!

Note: This tutorial has been tested on Android Studio 1.5 and 2.0

In short, the steps are, (2) Create simple project. (3) Import OpenCV SDK as a Module in Android Studio. (4) Set OpenCV Version. in Project (5) Fix Library association in project. (6) Done! Now actual OpenCV code can be written in future. The longer and detailed guided tutorial is given below.

  1. I beg you to open Android studio.
  2. Create a new project
    • I named it “OpenCV_Test”. (It could be different in the following GIF)
    • Minimum SDK is “API 19: Android 4.4 (KitKat).
    • Default Activity is “Basic Activity” (easily changeable later on)
    • Activity name is “MainActivity” (i.e. default settings)
    • I have shown the entire process in this GIF.
      Android-Studio-Create-New-Project
    • After pressing Finish, Gradle will perform some processes and eventually, you will be presented with your Android project.
    • Now, we can start importing OpenCV into the project.
  3. Import the OpenCV for Android SDK module in Android Studio.
    • To import the OpenCV SDK as a module in your project, go to File>New>Import Module.
    • Then Give path to your OpenCV as ..\OpenCV-android-sdk\sdk\java
    • You can chose to modify your module’s name.
    • Press Next and Finish the Dialogue.
    • The entire process is given here:
      OpenCV-Android-Import-Module-Android-Studio
    • Note that in the end, there are some errors in the code as well as the console. This is because you need to fix the Version number and link the libraries with your own project. This is shown in the next two steps.
  4. In this step, we will fix the Android Project SDK information in the OpenCV build.gradle file.
    • In project explorer, switch to Project view.
    • Go to OpenCVLibrary300 > build.gradle file and open it.
      • I have updated the contents of the file with the following code
        apply plugin: 'com.android.library'
        
        android {
            compileSdkVersion 23
            buildToolsVersion "23.0.2"
        
            defaultConfig {
                minSdkVersion 19
                targetSdkVersion 23
            }
        
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                }
            }
        }
      • Note that the android project’s SDK information can be obtained from the project’s own build.gradle file.
    • Once the Android SDK settings are updated, press “Try Again” button.
    • This entire process is given below:
      OpenCV-Android-Update-DefaultProject-SDK-Information
    • Now. we need to fix library association.
  5. Looking good so far! We now need to make sure that the OpenCV for Android libraries are associated with our Android Studio project. Currently, Android Studio will not recognize the OpenCV code that we type in our files. We fix this as follows.
    • Go to File>Project Structure.
    • When window opens, under Modules, select app.
    • Click Dependencies.
    • Click +.
    • Select Module Dependencies.
    • (In my case) Select :openCVLibrary300.
    • Press Ok and Ok.
    • After a few seconds, the libraries will be associated with your Android project.
    • This entire process is shown here:
      OpenCV-SDK-library-association
    • You can now write more OpenCV code in future in the same project.
  6. We did it! Project is ready for future OpenCV development.

This concludes this tutorial. You are now ready to start making your own Android Studio Project that consists of OpenCV SDK features limited only by your imagination. In the next tutorial, I will SHOW CAMERA on android app screen using OpenCV. Make sure that you read it. Do not forget to SHARE this post and write your opinions, ideas and views  in the  COMMENT  section below.

Thanks for reading :). Please like my Facebook page and follow my Twitter for more tutorials.

Return to OpenCV for Android Tutorials List

Categories
Android OpenCV Programming

OpenCV SDK for Android File Structure

Return to OpenCV for Android Tutorials List

In this tutorial, you will learn about the file structure of OpenCV SDK for Android. The information here is very short and lacks details. My purpose here is to provide just enough information to get going with the rest of the tutorials. I highly recommend reading more about the folders, algorithms, libraries and classes on your own.

OpenCV-for-Android-filestructure

So you have downloaded SDK but you may be curious what the SDK files do. Lets see to that now. You can skip this tutorial if you are interested in going directly to the development.

When you extract the “OpenCV-3.0.0-android-sdk-1.zip” from the precious tutorial, you will get a folder /OpenCV-android-sdk/.

Inside the /OpenCV-android-sdk/ folder, you will see:

  • /apk/
  • /samples/
  • /sdk/
  • LICENSE
  • README.android

Lets look at these in detail.

OpenCV for Android SDK file structure
OpenCV for Android SDK file structure

S.No
Name
Description

1

/apk/ This folder contains OpenCV manager API for different android device architectures. Chose the .apk file which is supported by your android device. Or simply download one from Google Play Store because that way, you will be downloading the apk file that is supported by your device/

2

/samples/ This folder contains sample android apps that you can install into your android device to test features of OpenCV. Also note that the source code of each sample is included in the /samples/ folder. It is a good place to start.

3

/sdk/ THE BRAINS OF OpenCV is here. I will explain about this folder below.

4

LICENSE Well, it can’t be said more precisely than what is written there as “By downloading, copying, installing or using the software you agree to this license.If you do not agree to this license, do not download, install,

copy or use the software.”

5

README.android Contains a link to online documentation, resources and feedback. Quiet handy!

http://opencv.org/platforms/android.html

Now that the root file structure of OpenCV is out of the way, we can now take a look at the SDK folder contents to give you the idea of what exactly what it and its contents do.

The /sdk/ folder contains the OpenCV API and libraries that will be used in your android project. You need these to perform all the functionalities that OpenCV offers in order to help you perform your Computer Vision related job.

Inside the SDK folder, in my case, there are three folders:

  1. /sdk/etc/
  2. /sdk/java/
  3. /sdk/native/

Lets look at the contents of SDK folder here:

S.No Name Description
1 /sdk/etc/ This folder contains the “memory” of OpenCV. Memory being like the brain-memory :D. See, as the time passed, the geniuses who made OpenCV for us to feast upon collected data and fine-tuned it for algorithms to use. That data is kept here.

For example, face detection requires some data which is compared with the picture snapped by your x-megapixel camera. That data is kept inside this folder.

2 /sdk/etc/haarcascades HAAR or HAAR-like-features is a folder where you put post-OpenCV-training data.

 

In this folder, you can find data files which contain data generated by training OpenCV in order to detect face, eyes, nose etc detection.

 

You too can create such data files if you wish to detect something such as legs, airplane, cracks on wall (edge detection), pacman, ****, *******, *******888*88* detection 😛

 

Lets say you wish to train OpenCV to detect face of a “sick” person. So you take pictures of a (e.g.) 1000 sick people (positive images) and then resize those picture to a same small size that is easy to process in bulk :D. Now you will also need pictures of people who are NOT sick.  Now, you will train OpenCV on that load of 1000 pictures plus the people who are not sick. This data is put in this folder to be used.

 

HAAR algorithm is very accurate but is slower as compared to LBP.

3 /sdk/etc/lbpcascades LBP stands for local binary pattern. This method is unique in a way that instead of using generated data to detect features (as was the case of HAAR), the LBP takes a pixel and finds the intensity of its neighbor pixels.

 

So lets say there is a pixel. Practically, each pixel has eight neighbor pixels, so our pixel also has eight surrounding pixels. Now, for each pixel, a binary value is obtained. The value of binary number depends on the comparison between the center pixel and its test-neighbor pixel.

 

If pixel intensity is greater than center pixel, then value is 1.

If pixel intensity is lesser than center pixel, then value is 0.

 

LBP algorithm is very fast, but least accurate.

4 /java/ When creating a new Android project, you can import the OpenCV Java Api from this folder.
5 /java/.settings Contains settings that are implemented when importing the OpenCV for android Java API.
6 /java/gen Contains generated files. For example, R.java, when generated is put here.
7 /java/javadoc This folder contains the documentation of OpenCV for Android. In my case, it is the documentation for the version 3.0.0

All the classes of OpenCV for Android are explained here. So if you ever find yourself in trouble, or wish to learn more, visit this folder.

8 /java/res Standard Android project folder that contains resources to be used in an android project. The resource file that came in my case contains camera information.
9 /java/src The /etc/ folder was the memory of OpenCV. But this folder is the actual brain of OpenCV. This folder contains the classes that perform all the functionalities of OpenCV in Android. Classes are written in Java.

 

Root files are self explainatory. If not, then what on Earth are you doing on this post? You should learn Android and then come here.

10 /java/src/org/opencv Exactly this folder contains the classes. Core, mathematical operation algorithm, training and all the shit that OpenCV gets done for you, is actually here. Every improvement in OpenCV is included here. Please respect the contents of this folder if you use OpenCV.
11 /native/ This folder contains C++ .h (header) files and native libraries for multiple android architectures.

This is it for this tutorial. I have explained to you the structure of the OpenCV for Android SDK file structure. In the next tutorial, I will explin to you about the classes available in OpenCV for Android SDK which you can use.

Return to OpenCV for Android Tutorials List

Categories
Android OpenCV Programming

OpenCV for Android: Download Required Software

Return to OpenCV for Android Tutorials List

In this tutorial, you will learn which tools to download for creating your OpenCV project in Android Studio if you follow this tutorial series 🙂

  1. Download and install Android Studio from HERE. Make sure that it is working.
  2. Download  OpenCV for Android SDK from HERE.
    • Demonstration of SDK download.

      OpenCV for Android Download-Required Software
      OpenCV for Android Download-Required Software
  3. Basically, after downloading the SDK, simply extract it on a folder and it will be ready for usage.
  4. That’s it! You have downloaded the OpenCV for Android SDK.

In the next tutorial, you will make a new project and set it up so that your application is ready to OpenCV!

Return to OpenCV for Android Tutorials List

Categories
Codeigniter Programming

CodeIgniter 3 Tutorial 1: Download, Installation, Introduction and Welcome!

Back to CodeIgniter Tutorials

This is the first part of CodeIgniter 3 tutorials. CodeIgniter 3.0 introduced a lot of upgrades over 2.x versions of CodeIgniter. Users who wish to upgrade to CodeIgniter 3 may have to perform changes as mentioned here in the official CodeIgniter 3.0 documentation.

Here are my Tutorials for CodeIgniter:

CodeIgniter 3 Tutorials
CodeIgniter 2.2 Tutorials

This tutorial series is for new users of CodeIgniter users who wish to start with CodeIgniter 3.x. We will start with downloading Codeigniter.

CodeIgniter can be obtained from any of the two places.

  1. Official Website Here
  2. Official Github Repository Here

Lets download from the official website

Now, install XAMPP as I have explained here and also here for my CodeIgniter 2.2 Tutorials Series.

Now, once you have installed XAMPP and downloaded CodeIgniter 3, we can now start installing CodeIgniter. Follow the following steps.

  1. Assuming you installed XAMPP in D:\, go to D:\xampp\htdocs
  2. For this example, create a subfolder “tutorial” so we now have,
    D:\xampp\htdocs\tutorial
  3. Now, extract the contents of downloaded CodeIgniter files here.
  4. You will now have the following base structure of CodeIgniter.
  5. CodeIgniter is INSTALLED!
  6. Here is the simple explanation of all of these files and folders (You can skip if you are already familiar otehrwise, I highly recommend reading the brief descriptions below):
    1. \application\
      (108Kb, 45 Files)
      This folder contains the web application that you will develop using CodeIgniter.
    2. \system\
      (2.05MB, 202 Files)
      This folder contains the actual CodeIgniter framework. In other words, the cool stuff! It is not necessary, but it would be nice to open this folder by yourself and see how everything works behind the scenes. Also, this is the folder that is affected with each version. So yuou might be required to make changes to this folder if you ever wish to upgrade.
    3. \user_guide\
      (6.41MB, 191 Files)
      This folder contains the latest CodeIgniter documentation at the time of release of whichever version that you downloaded. It is SAFE TO DELETE this folder at the cost of losing offline official guide. I personally delete these from my projects to save size.
    4. \.gitignore
      This file tells Github to ignore the specified files and folders to be ignored when committing to a repository.
    5. \composer.json
      This file is used with composer to keep the packages up to date.
    6. \contributing.md
      Simply put, this is a readme file for “contributing to the CodeIgniter project” topic.
    7. \index.php
      This file contains variables that control how your application behaves. For example,

      1. Error Reporting levels
      2. \system\ folder name (which it allows to be changed)
      3. Want to know how to change \application\ folder name? This file does it!
      4. Want to move the \application\view\ folder out of the \application\ folder? index.php does it!
      5. Override application routing.
      6. Meddle with the config parameters.

 

And some more parameters which should not be touched and if you did, then God help you.

 

    • \license.txt
      Legal stuff about CodeIgniter Project
    • \readme.rst
      Official Readme of the CodeIgniter project!
    • You will see the following default welcome screen:

Back to CodeIgniter Tutorials