Pagination component using Laravel5.3 and Vue Js


In These days i am working in Laravel for backend and Vue js for the front end. I just made the custom pagination component which is reusable for the entire application. It is easy to make custom pagination component using Vue Js and Laravel. How I did that work i am going to describe in this post.


Here is the github link of my project which i am done :).

Ok at  first download the Fresh Laravel app using command

composer create-project laravel/laravel paginate-work

                     or
laravel new paginate-work

Go up to your mysql and create database, let's say name database as paginate. and then open your laravel project in IDE  like sublime text or phpstorm. Add all the required database credentials in the .env file.


Now go up to your project directory from your command line and run the command php artisan migrate That migrate some default tables, you can see these tables inside of database paginate  in phpmyadmin.

Now Import Data using ModelFactory, In Laravel5.3 there is database/factories/ModelFactory.php file there is set up for generate random users. Now In command line run command php artisan tinker
and  there will appear special type of interface for tinker run command factory('App\User', 1000)->create();  And then 1000 random users will be generated.

I really want to generate the auth scaffold using command php artisan make:auth, I am using master file as a template that's why i generate the scaffold.

It's time to create a route file, for the vue api, i create one route and for the listing and paginating of users i am creating the another route and two separate controllers. Here is routes in routes/web.php file



Create the API directory inside controllers folder create controller UserAPIController using command php artisan make:controller API/UserAPIController  Now make constructor and initialize instance of User model. and return the paginated value in json format in this way.



Let's create a users.js inside public/js directory. At First Create the component and write code for template and props in this way.




Create UserController and make index method inside of it and return to the view page using this way



For the data, computed methods and methods required to the template are written after props in this way.



It's time to create main instance of Vue js and pass the users data using vue resource.




Inside resources/views/layouts/app.blade.php write something like this code . This is used as a master file only.



Create users directory inside of resources/views and create index.blade.php file and Write following Code



Now It's time to get the result so go up to your project directory using command line and run command php artisan serve  app will run on port 8000. See using localhost:8000 url on your browser. you are good to go.

Here I am using props and vue pagination component this is resuable so if we need to make another pagination for another table we can just add this component.

<vue-pagination  :pagination="pagination"   v-on:click="getUsers(pagination.current_page)" :offset="4"></vue-pagination>

getUsers(pagination.current.page) this method may differ otherwise it works for other tables too if you are using vue js to get the data.

Here is the github link of my project which i am done :).

Ok It's mid night I have to sleep. Happy Coding !

Chart Js is cool


The next day of tomorrow will be my final year project's final submission presentation. Our team successfully make a good documentation for our application and we are making our app using laravel and angular It is not more awesome but it's ok. In any application there need to be make reports which can summarize the results or status of the application. Data visualization is required because manager has no more time to see every status, Manager can see the visual things and get the information about the system or organization that's why we need to make reports.

In my Final year project  main remaining part is reports, And I started to make reports using chart js. today I just copy and pasted code to my application and make the line chart, bar diagram and pie chart. Which is awesome and lots of flexible to make. Today I just make these diagrams using static data. Tomarrow I will add from my database.

ChartJs is Cool and Awesome .

Data Import to the database using CSV File in Laravel5.2

Data importing in database using csv file in using laravel5.2 is quite easy. Today I spend some couple of minutes to learn about data import using csv file. How I did that work , I am gonna describe here.

At first i download the laravel project using composer, then i create the mysql database using phpmyadmin and I configure the database credentials in .env file. 

Now I just created the user.csv file inside of the public directory and add some comma separated values. These values is based on the user information whose table structure or migration file is provided by the laravel by default. The File is something like this

 


I just run the migration file using command php artisan migrate command and made some route configuration in routes.php file which is something like this.



In above figure shows that routing for the importing csv file, Here I am not using controller for the importing Because I created this project for learning purpose. In which fopen() function is used to open the user.csv file and fgetcsv() function is used to fetch data from csv file to store into database.

I can run this project using base_url/csv  then it will import all the data of user.csv file. and show all the result to the browser because it return the User::all() values. Thanks ! I learned it ! Keep On Working !!!!

Laravel Project Virtual Hosting in Linux mint

From a couple of days i have been working on voting_lession which is the tutorial series of laracasts.com .  And i really wanted to make virtual hosting of my projects But I thought i should install homestead and VirtualBox and other some tools. Actually my PC is quite slow so i do not want to install that tools. Finally i got the idea of virtual hosting using the apache server and today i implement the virtual hosting for the laravel project. How i configure and make virtual hosting that's gonna be describe here.


First I configure the file of 000-default.conf file which is inside of /etc/apache2/sites-available folder. I choose communitylink.com.np domain name and the project folder is inside of /var/www/html folder. Let's see the configuration file 000-default.conf




It's time to make some changes in the hosts file which is also inside of the /etc directory. In this file just add the domain name as following



I am not putting the voting_lession project directory inside of the /var/www/html folder I want to create the symbolic link for that, My real project is inside of the /home/madhu/Workspace/Laravel/voting_lession now I create the symbolic link in using following command

 ln -s /home/madhu/Workspace/Laravel/voting_lession  /var/www/html/

Now  it creates the symbolic link, I should restart the apache server using the following command.

sudo /etc/init.d/apache2 restart

and then enter communitylink.com.np on the browser, It will works for me ! Thanks !






Eloquent Model Testing in Laravel

In these days software testing is essential for the software development process, TDD, BDD etc are the popular methods of Software Testing. In TDD at first we write the test functions and then we will make functions which need to pass the tests. In These days i am learning about TDD in which some of the testing such as unit testing, integration testing, regression testing . I am weak in software testing  But Software testing is fun and interesting for me at this time. Using TDD it ensures my code is correct and reliable code that's why i need to use testing.

Today I am watching the video tutorials from Laracasts.com, I understand some testing jargon about the Eloquent Model Testing in Laravel In the following way.

First I downloaded the Laravel project and create database in phpmyadmin and  configure for the database  credentials in .env file of the laravel.

Now i Create a simple Article Model and migration file for articles table using the command php artisan make:model Article -m   

I am Just added just these columns for the articles table, Which is shown in the below figure.



And Just create the table using the commands php artisan migrate:install and php artisan migrate.
Now tables are created in the database.

Now create the factory method inside of the ModelFactory.php which will useful to add the records in the database tables. I am making the factory method for the articles table, which is shown follwing.




For the Model Test I create the  test class ArticleTest.php inside of the tests/integration/models folder and test class is as follows.

 

Now If i run the test using the phpunit  command then it Sure fails Because I do not created the trending() function in the Article.php Model. In above testing shows that At First two articles are created using the factory method, one article created with value of 10 in the reads column and another article is created with value of 20 in the reads column. After then trending() method is called and stored the result in $articles variable. Now actual comparing started using the assertEquals and assertCount methods which is quite simple. Ok How trending() method is organized in the Article.php is shown below.



Now Run the phpunit and my test will work. The Source code is available in github in this link https://github.com/madhusudhan1234/testing-lession

The PHP cURL extension must be installed to use Guzzle.

I have been Pause my Project Work from one month before, From Today I am started to continue my final year project. I paused my work because i spend time  for my exam at that time. My Project is social media type of web application which connect the service seeker and Service Provider at one place and make their business easier, and main another purpose is to provide the information which kinds of information users wants to see. Which is made using the Laravel Framework, At the time of starting of my project i use the php version 5.6.14 but meantime i upgrade the php verison to 7.0, After upgrading  I change the some configuration and make project work in that environment. But When I start to continue work for my project today, I got some another extra Problems. One of the Problem is Shown in below figure.



I am Just Install all the php7 related cURL on my computer But the problem is still stay in the application. I studied and learn about what is cURL in php, cURL is a Command Line Tool which is used to communicate external server, upload files using ftp, Send Mail etc. so It is essential for my project .

Now I solve the problem by following steps, I am Using Linux Mint as an OS

  • I search the php.ini file for the configuration of cURL
  • I got that file inside of /etc/php/7.0/cli folder
  • Uncomment the "extension=php_curl.dll" line
  • Restart the Apache Server using the command "sudo /etc/init.d/apache2 restart"
  • And I start my application using "php artisan serve"
  • It Works, And Solved the cURL Problem
Ok Thank you ! Happy Coding, Keep Working on Problem Solve !

No Meaning of Research without the result

In these days, I am involving in final year project, For this project our group members are working hardly. We are getting knowledge by studying different blogs, posts, tutorials or by watching video tutorials and some experiments. We can not do any work without knowing it’s core concept. We are beginner so we must need to search or study lots of different kinds of stuffs. And we are working on project by research work. How the research will work for our project by research work. what happen if we can not get conclusion and result by involving in research work that things I am going to describe here .

According to the syllabus of the our final year project we need to make documentation first and then start the technical part of the application. We just finish some part of the documentation and the some part of the technical stuff . Obviously we searched the different kinds of things to do for the project work. But we have to study lots of things which are required for our work, We are going to make something special not just CRUD app. If we study surface about the topic and terms and simply copy paste to the documentation that never going to help for our skill and career. We need to understand what we are doing right now . Some People seems to be wild researcher , Always research on the internet but not going to give the conclusion from research of his/her study, That does not make sense or does not going to help anybody. It’s just like someone is researching about how to cook food, research completed but does not know how to cook food. There is no meaning of research in that case. It’s very hard to understand all the things at beginning time. If we going to the detail of the topic we will clear about the topic we need to dive into until we get the conclusion.

Again I want to give example of research on cooking food, if you want to research or experiment about cooking food you just understand what type of food you are going to prepare. After that list out the required ingredients just know procedure to how to cook that. After study and analysis you must do experiment to cook food by following the procedure and rules. You may be success or fail to cook food if you got success we have to try to make better taste and more awesome otherwise you have to try to cook food again. It is better if you get success and get knowledge about how to do it. It will be best if you help or encourage to cook food who are interested at the work if you only know how to cook food that’s good because you know it . if you teach or encourage other you will get the community or team that makes your and your team mates skill up very quick.

Conclusion:
Deep Study is required for the any type of research work we are going to success in our final year project. We are going to achieve it by bringing the strong conclusion after of research work.