Posts

Steps to set up a new Laravel app, initialize a git repo, push to Github

Image
This is a list of steps to: Setup a new Laravel app Initialize a local repository using git Create a new remote repository using GitHub Change README.rdoc Assumptions: PHP is installed Composer is installed Git is installed Github account is established Setup a new Laravel app Navigate to the directory in which you want the new app created using 'change directory' (cd). Use the 'make directory' (mkdir) command if you want to create a new directory, such as laravel_projects (Note: Laravel will automatically create a directory for all your app files)   $ cd <correct_directory>   Create a new app. It's good practice to append your new app name with 'blog' so that it will not be confused with any classes you create later. Installing Laravel Laravel utilizes  Composer  to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine. Via Laravel Installer ...

How to check request is Ajax or not in Laravel 5

Sometimes, we need to check request is ajax or not in Laravel 5. If you want to call the same method but if the request is ajax then you perform differently, then you can do by using $request object. In Laravel 5 $request object provides a method to check request is ajax or not, In the following example you can see how it works. You can check directly from Request facade and also from the request object, both are same, so let's see below example. Example 1: public function index(Request $request) {     if ($request->ajax()){         return response()->json(['ajax']);     }     return response()->json(['http']); } Example 2: public function index() {     if (Request::ajax()){         return response()->json(['ajax']);     }     return response()->json(['http']);...

Laravel 5 task scheduling with cron job example

Image
If you want to execute scheduling jobs in specific time and specific interval then you can apply cron job which is a Unix command.We can manage a task in the server that executes scripts which helps in sending daily/weekly reports from our website. The main use of cron job is in cleaning up the databases, sending the emails, executing the time-consuming tasks etc. We can simply delete files from the database with the help of Cron Job. A Cron job will only work on Unix based machines. It consists of a configuration file called Crontable which is also known as Crontab. This Crontab is used to manage the scheduling and consists of different cron jobs and each of the cron jobs is associated with a specific task. Generate A New Command Class : First, we will generate our own custom commands by running following commands which will generate a class in the app/Console/Commands/ directory. php artisan make: console CustomCommand After running this command you will...

Laravel 5 import export to excel and csv using maatwebsite

Image
In this post, i will show you how to import excel or CSV to store in database and how to export or download excel or CSV file from database table by maatwebsite. maatwebsite packages through you can easily get data, also you can group by data, also create more than one sheet etc. so now I show you simple example of books table data, you can download in xls, xlsx and csv formate and also you import data in xls, xlsx and CSV format file. In following few step you can implement import and export both function in your project.  Step 1: Installation Open your composer.json file and add below line in required package. Laravel 5 "maatwebsite/excel": "~2.1.0" Laravel 4 "maatwebsite/excel": "~1.3" Then, run command composer update Now open config/app.php file and add service provider and aliases. 'providers' => [                 ....                 'Maatwebsite\E...

Laravel after login, redirect back to previous url

If you are working on laravel and you want to do like: How to redirect back to the previous URL, After login. after login user, you can redirect his previous page as he was before. you can do this, I would like to give you two example. the first example is using intended() and the second one is using session but I don't know more but I think intended() is not working properly in laravel 5 but you can try in laravel 4. but I am sure I gave you an example with the session that works well in both. So, you can try anyone and get your solution, 1. using intended() and 2. session. Example 1: public function loginPost() {     if ($this->auth->attempt(array('email' => Input::get('email'), 'password' => Input::get('password')))){         return Redirect::intended();     }     return back(); } Example 2: public function login() {      ...

Mysql storedprocedure with pagination in laravel 5

You are working on laravel with MySQL database. you had created MySQL stored procedure for get data and you want to call procedure with pagination in laravel 5 then you can not directly make pagination as laravel document.If you are using directly MySQL stored Procedure in your controller, model or repository and you want to give pagination like this way :     $data = DB::select(DB::raw('CALL store("6pm")'))->paginate(5);   This way you found error in your Laravel 5 website. we can't give directly this way pagination because your procedure will get all the data from database. but we can give pagination this way :     $pageNumber = Input::get('pageNumber', 1);      $paginate = 2;             $data =  DB::select(DB::raw('CALL store("6pm")'));          $offSet = ($pageNumber * $paginate) - $paginate;   ...

How to check Object is empty or not in Jquery/JavaScript ?

you can check your JavaScript OR jQuery object is empty or not, because we need to check many place our jQuery object is empty, null or undefined etc., So usually, we can check using $.isEmptyObject() as i explained as under. how to check empty object in javascript, how to check empty object in jquery, jQuery.isEmptyObject() example, jquery check object is null, jquery check object is empty, jquery check object is empty or not, how to check json object is empty or not in jquery, check if json object is empty jquery if($.isEmptyObject(your_object)){    alert("This Object is empty!"); }else{   alert("This Object is not empty!"); } you can also check other way to your object is empty or not i also describe under. if (your_object && your_object instanceof Array && !your_object.length) {    console.log('This Object is empty!'); } else {    console.log('This Object is not empty!'); }