Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

Laravel 5/6/7 Angular JS CRUD Example With File Upload

April 19, 2020 Pakainfo Laravel, AngularJS Leave a comment

Today, We want to share with you Laravel 5/6/7 Angular JS CRUD Example With File Upload and Pagination.In this post we will show you laravel angularjs crud example, hear for angularjs laravel crud we will give you demo and example for implement.In this post, we will learn about laravel and angularjs together with an example.

Laravel 5/6/7 Angular JS CRUD Example With File Upload and Pagination

Contents

  • Laravel 5/6/7 Angular JS CRUD Example With File Upload and Pagination
    • Phase 1 Make a tasks table and module
    • Phase 2 Make a controller
    • Phase 3 Route file
    • Phase 4 use AngularJS
    • Phase 5 Make a View
    • Read
    • Summary
    • Related posts

There are the Following The simple About laravel and angular crud operation Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to integrate angularjs with laravel, so the angularjs with laravel is used for this example is following below.

Laravel is a web application framework with expressive, elegant syntax.The PHP Framework for Web Artisans,freeing you to create without sweating the small things. CRUD Operation With Server Side.

Keywords : Laravel and AngularJS CRUD with Search and Pagination Example, laravel angularjs login example, angular laravel pagination, angularjs with laravel, how to integrate angularjs with laravel, laravel and angularjs together, laravel and angular crud operation, angularjs laravel crud, laravel angularjs crud example

Phase 1: Make a tasks table and module

create migration for tasks table using Laravel 5 php artisan command

php artisan make:migration create_tasks_table

database/migrations

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTasksTable extends Migration
{
    public function up()
    {
        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('description');
            $table->timestamps();
        });
    }
    public function down()
    {
        Schema::drop("tasks");
    }
}

app/Task.php

namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class Task extends Model
{
    public $fillable = ['title','description'];
}

Phase 2: Make a controller

app/Http/Controllers/TaskController.php


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Task;
class TaskController extends Controller
{
    public function index(Request $request)
    {
        $input = $request->all();
        if($request->get('search')){
            $tasks = Task::where("title", "LIKE", "%{$request->get('search')}%")
                ->paginate(5);      
        }else{
		  $tasks = Task::paginate(5);
        }
        return response($tasks);
    }
    public function store(Request $request)
    {
    	$input = $request->all();
        $create = Task::create($input);
        return response($create);
    }
    public function edit($id)
    {
        $task = Task::find($id);
        return response($task);
    }
    public function update(Request $request,$id)
    {
    	$input = $request->all();
        Task::where("id",$id)->update($input);
        $task = Task::find($id);
        return response($task);
    }
    public function destroy($id)
    {
        return Task::where('id',$id)->delete();
    }
}

Phase 3: Route file

app/Http/routes.php

Route::get('/', function () {
    return view('app');
});
Route::group(['middleware' => ['web']], function () {
    Route::resource('tasks', 'TaskController');
});
// Templates
Route::group(array('prefix'=>'/templates/'),function(){
    Route::get('{template}', array( function($template)
    {
        $template = str_replace(".html","",$template);
        View::addExtension('html','php');
        return View::make('templates.'.$template);
    }));
});

Phase 4: use AngularJS

public/app/route.js

var app =  angular.module('main-App',['ngRoute','angularUtils.directives.dirPagination']);
app.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.
            when('/', {
                templateUrl: 'templates/home.html',
                controller: 'AdminController'
            }).
            when('/tasks', {
                templateUrl: 'templates/tasks.html',
                controller: 'TaskController'
            });
}]);

public/app/controllers/TaskController.js

app.controller('AdminController', function($scope,$http){
  $scope.pools = [];
});
app.controller('TaskController', function(dataFactory,$scope,$http){
  $scope.data = [];
  $scope.taskLibsData = {};
  $scope.totalTasksTemp = {};
  $scope.totalTasks = 0;
  $scope.pageChanged = function(newPage) {
    FetchTaskRowsPage(newPage);
  };
  FetchTaskRowsPage(1);
  function FetchTaskRowsPage(pageNumber) {
      if(! $.isEmptyObject($scope.taskLibsData)){
          dataFactory.httpRequest('/tasks?search='+$scope.searchText+'&page='+pageNumber).then(function(data) {
            $scope.data = data.data;
            $scope.totalTasks = data.total;
          });
      }else{
        dataFactory.httpRequest('/tasks?page='+pageNumber).then(function(data) {
          $scope.data = data.data;
          $scope.totalTasks = data.total;
        });
      }
  }
  $scope.searchDB = function(){
      if($scope.searchText.length >= 3){
          if($.isEmptyObject($scope.taskLibsData)){
              $scope.taskLibsData = $scope.data;
              $scope.totalTasksTemp = $scope.totalTasks;
              $scope.data = {};
          }
          FetchTaskRowsPage(1);
      }else{
          if(! $.isEmptyObject($scope.taskLibsData)){
              $scope.data = $scope.taskLibsData ;
              $scope.totalTasks = $scope.totalTasksTemp;
              $scope.taskLibsData = {};
          }
      }
  }
  $scope.saveAdd = function(){
    dataFactory.httpRequest('tasks','POST',{},$scope.form).then(function(data) {
      $scope.data.push(data);
      $(".modal").modal("hide");
    });
  }
  $scope.edit = function(id){
    dataFactory.httpRequest('tasks/'+id+'/edit').then(function(data) {
    	console.log(data);
      	$scope.form = data;
    });
  }
  $scope.saveEdit = function(){
    dataFactory.httpRequest('tasks/'+$scope.form.id,'PUT',{},$scope.form).then(function(data) {
      	$(".modal").modal("hide");
        $scope.data = apiModifyTable($scope.data,data.id,data);
    });
  }
  $scope.remove = function(task,index){
    var result = confirm("Are you sure delete this task?");
   	if (result) {
      dataFactory.httpRequest('tasks/'+task.id,'DELETE').then(function(data) {
          $scope.data.splice(index,1);
      });
    }
  }
});

public/app/helper/taskHelper.js

function apiModifyTable(originalData,id,response){
    angular.forEach(originalData, function (task,key) {
        if(task.id == id){
            originalData[key] = response;
        }
    });
    return originalData;
}

create one another folder “packages” and create file dirPagination.js(public/app/packages/dirPagination.js) and put code of following link:dirPagination.js

Also Read This 👉   Laravel 6 Remove public from URL

public/app/services/taskServices.js

app.factory('dataFactory', function($http) {
  var myService = {
    httpRequest: function(url,method,params,dataPost,upload) {
      var passParameters = {};
      passParameters.url = url;
      if (typeof method == 'undefined'){
        passParameters.method = 'GET';
      }else{
        passParameters.method = method;
      }
      if (typeof params != 'undefined'){
        passParameters.params = params;
      }
      if (typeof dataPost != 'undefined'){
        passParameters.data = dataPost;
      }
      if (typeof upload != 'undefined'){
         passParameters.upload = upload;
      }
      var promise = $http(passParameters).then(function (response) {
        if(typeof response.data == 'string' && response.data != 1){
          if(response.data.substr('loginMark')){
              location.reload();
              return;
          }
          $.gritter.add({
            title: 'Application',
            text: response.data
          });
          return false;
        }
        if(response.data.jsMessage){
          $.gritter.add({
            title: response.data.jsTitle,
            text: response.data.jsMessage
          });
        }
        return response.data;
      },function(){
        $.gritter.add({
          title: 'Application',
          text: 'An error occured while processing your request.'
        });
      });
      return promise;
    }
  };
  return myService;
});

Phase 5: Make a View

resources/views/app.blade.php

<html lang="en">
<head>
	<title>Laravel 5/6/7 CRUD</title>
	<!-- Fonts -->
	<link href='//fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
	<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
	<!-- Angular JS -->
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>  
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-route.min.js"></script>
	<!-- MY App -->
	<script src="{{ asset('/app/packages/dirPagination.js') }}"></script>
	<script src="{{ asset('/app/routes.js') }}"></script>
	<script src="{{ asset('/app/services/taskServices.js') }}"></script>
	<script src="{{ asset('/app/helper/taskHelper.js') }}"></script>
	<!-- App Controller -->
	<script src="{{ asset('/app/controllers/TaskController.js') }}"></script>
</head>
<body ng-app="main-App">
	<nav class="navbar navbar-default">
		<div class="container-fluid">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
					<span class="sr-only">Toggle Navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="#">Laravel 5.2</a>
			</div>
			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav">
					<li><a href="#/">Home</a></li>
					<li><a href="#/tasks">Task</a></li>
				</ul>
			</div>
		</div>
	</nav>
	<div class="container">
		<ng-view></ng-view>
	</div>
</body>
</html>

1.resources/views/templates/home.html

<h2>Welcome to Home Page</h2>

2.resources/views/templates/tasks.html

<div class="row">
    <div class="col-lg-12 margin-tb">
        <div class="pull-left">
            <h1>Task Management System</h1>
        </div>
        <div class="pull-right" style="padding-top:30px">
            <div class="box-tools" style="display:inline-table">
              <div class="input-group">
                  <input type="text" class="form-custom-control input-sm ng-valid ng-dirty" placeholder="Search" ng-change="searchDB()" ng-model="searchText" name="table_search" title="" tooltip="" data-original-title="Min character length is 3">
                  <span class="input-group-addon">Search</span>
              </div>
            </div>
            <button class="btn btn-success" data-toggle="modal" data-target="#create-user">Make a New</button>
        </div>
    </div>
</div>
<table class="table table-bordered pagin-table">
    <thead>
        <tr>
            <th>No</th>
            <th>Task Title</th>
            <th>Task Description</th>
            <th width="220px">Action</th>
        </tr>
    </thead>
    <tbody>
        <tr dir-paginate="value in data | tasksPerPage:5" total-tasks="totalTasks">
            <td>{{ $index + 1 }}</td>
            <td>{{ value.title }}</td>
            <td>{{ value.description }}</td>
            <td>
            <button data-toggle="modal" ng-click="edit(value.id)" data-target="#edit-data" class="btn btn-success">Edit</button>
            <button ng-click="remove(value,$index)" class="btn btn-danger">Delete</button>
            </td>
        </tr>
    </tbody>
</table>
<dir-pagination-controls class="pull-right" on-page-change="pageChanged(newPageNumber)" template-url="templates/dirPagination.html" ></dir-pagination-controls>
<!-- Make a Modal -->
<div class="modal fade" id="create-user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form method="POST" name="addTask" role="form" ng-submit="saveAdd()">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel">Make a Task</h4>
            </div>
            <div class="modal-body">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-6 col-md-6">
                            <strong>Task Title : </strong>
                            <div class="form-group">
                                <input ng-model="form.title" type="text" placeholder="Name" name="title" class="form-custom-control" required />
                            </div>
                        </div>
                        <div class="col-xs-12 col-sm-6 col-md-6">
                            <strong>Description : </strong>
                            <div class="form-group" >
                                <textarea ng-model="form.description" class="form-custom-control" required>
                                </textarea>
                            </div>
                        </div>
                    </div>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" ng-disabled="addTask.$invalid" class="btn btn-success">Submit</button>
                </div>
            </div>
            </form>
        </div>
    </div>
</div>
</div>
<!-- Edit Modal -->
<div class="modal fade" id="edit-data" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form method="POST" name="editTask" role="form" ng-submit="saveEdit()">
                <input ng-model="form.id" type="hidden" placeholder="Name" name="name" class="form-custom-control" />
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel">Edit Task</h4>
            </div>
            <div class="modal-body">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-6 col-md-6">
                            <div class="form-group">
                               <input ng-model="form.title" type="text" placeholder="Name" name="title" class="form-custom-control" required />
                            </div>
                        </div>
                        <div class="col-xs-12 col-sm-6 col-md-6">
                            <div class="form-group">
                               <textarea ng-model="form.description" class="form-custom-control" required>
                                </textarea>
                            </div>
                        </div>
                    </div>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" ng-disabled="editTask.$invalid" class="btn btn-success create-crud">Submit</button>
                </div>
            </div>
            </form>
        </div>
    </div>
</div>
</div>

3.resources/views/templates/dirPagination.html

<ul class="pagination pull-right" ng-if="1 < pages.length">
    <li ng-if="boundaryLinks" ng-class="{ disabled : pagination.current == 1 }">
        <a href="" ng-click="setCurrent(1)">«</a>
    </li>
    <li ng-if="directionLinks" ng-class="{ disabled : pagination.current == 1 }">
        <a href="" ng-click="setCurrent(pagination.current - 1)">‹</a>
    </li>
    <li ng-repeat="pageNumber in pages track by $index" ng-class="{ active : pagination.current == pageNumber, disabled : pageNumber == '...' }">
        <a href="" ng-click="setCurrent(pageNumber)">{{ pageNumber }}</a>
    </li>
    <li ng-if="directionLinks" ng-class="{ disabled : pagination.current == pagination.last }">
        <a href="" ng-click="setCurrent(pagination.current + 1)">›</a>
    </li>
    <li ng-if="boundaryLinks"  ng-class="{ disabled : pagination.current == pagination.last }">
        <a href="" ng-click="setCurrent(pagination.last)">»</a>
    </li>
</ul>

Web Programming Tutorials Example with Demo

Read :

  • Jobs
  • Make Money
  • Programming
Also Read This 👉   Eloquent orwhere Query Use in Laravel

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about angular laravel pagination.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related posts:

  1. File upload and sending data to backend using angular js
  2. Insert update delete Using Laravel 5.2 Ajax CRUD laravel without refresh page
  3. Laravel 6.2 jQuery AJAX CRUD Tutorial
  4. Vue js Laravel 5.8 File Upload Tutorial
  5. Laravel Vue JS CRUD Example Tutorial From Scratch
  6. Multiple File Upload in laravel 7 Example Tutorial
  7. Laravel Vue JS ajax file upload multipart form data
  8. File Upload in Laravel 7 Example Tutorial
angular laravel paginationAngularJSangularjs laravel crudangularjs with laravelcodecrudexamplehow to integrate angularjs with laravellaravel 5laravel 5 and angularjs crudlaravel 5 and angularjs crud search and paginationlaravel 5 and angularjs paginationlaravel 5 and angularjs searchLaravel 5.2laravel 5.2 and angularjs crud examplelaravel and angular crud operationLaravel and AngularJS CRUD with Search and Pagination Examplelaravel and angularjs togetherlaravel angularjs crud examplelaravel angularjs login examplepaginationphpsearch

Post navigation

Previous Post:Laravel 5/6/7 Import & Export data to Excel CSV using maatwebsite
Next Post:onclick update database in laravel

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (93) Education (63) Entertainment (130) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2345) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (147) Technology (2416) Tips and Tricks (130) Tools (214) Top10 (507) Trading (95) Trending (77) VueJs (250) Web Technology (113) webtools (200) wordpress (166) World (343)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites