Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel

Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel Crud application in laravel 


 C:\xampp\htdocs\laravel\routes\web.php



<?php


use Illuminate\Support\Facades\Route;


/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/



use App\Http\Controllers\ArticleController;

Route::get('/articles' , [ArticleController::class,'showData']);

Route::get('/articles/add' , [ArticleController::class,'add']);

Route::post('/articles/add' , [ArticleController::class,'SaveArticles']);

Route::get('/articles/remove/{id}' , [ArticleController::class,'RemoveArticles']);

Route::get('/articles/update/{id}' , [ArticleController::class,'UpdateArticles']);

Route::get('/articles/update' , [ArticleController::class,'UpdateArticlesget']);

Route::post('/articles/update_data' , [ArticleController::class,'UpdateArticlesData']);

Route::get('/', function () {

    return view('welcome');

});

?>

///Database connection .env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:00sdlSwyCqjGq/TaeRDJfT1iWiU6BlyL2l1aAMQPM8Q=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
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
FILESYSTEM_DRIVER=local
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=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"





C:\xampp\htdocs\laravel\app\Models


<?php 
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Article extends Model{
protected $table ='articles';
}
?>


C:\xampp\htdocs\laravel\app\Http\Controllers\ArticleController.php


<?php
 
namespace App\Http\Controllers;
 use App\Models\Article;
use Illuminate\Http\Request;
 
class ArticleController extends Controller
{
  
     function showData()
    {
        $articles = \App\Models\Article::all();
  
        return view('list')->with('articles', $articles);
       // return view('list');
    }
    function add()
    {
      return view('add');
    }
    function SaveArticles(Request $request){
      //print_r($_POST);
              //dd($request->all());
        $article = new Article;
        //print_r($article);
        $article->name=$request->name;
        $article->email=$request->email;
         $article->mobile=$request->mobile;
         $article->save();
         $request->Session()->flash('msg','Data added');
         return redirect('articles');

    //echo "Insert Successful!";
    }
     function RemoveArticles($id) {

        $article = \App\Models\Article::find($id);

        $article->delete();
            
        return redirect('articles');
       // echo "Delete Successful!";

}
function UpdateArticles($id, Request $request){
      $articles = \App\Models\Article::find($id);
      return view('update')->with('articles', $articles);
  // $articles=Article::where('id',$id)->first();
   // return view('update')->with(compact(varname:'articles'));

}
function UpdateArticlesData(Request $request){
//echo "hello";
     $article = \App\Models\Article::find($request->id);
       //   $article = new Article;
        //print_r($article);
        $article->name=$request->name;
        $article->email=$request->email;
         $article->mobile=$request->mobile;
         $article->save();
         //echo "update";
           $request->Session()->flash('msg','Data Updated');
         return redirect('articles');

}
}




view section



C:\xampp\htdocs\laravel\resources\views

add.blade.php

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Laravel Crud</title>

<link rel="stylesheet" type="text/css" href="{{asset('assets/css/bootstrap.min.css')}}">

<script type="text/javascript" src="{{asset('assets/js/bootstrap.min.js')}}"></script>

</head>

<body>

<nav class="navbar bg-dark bg-light">

  <div class="container-fluid">

    <a class="navbar-brand text-white">Welcome Laravel</a>

   

  </div>

</nav>

<div class="container">

<div><br></div>

<form method="post" action="{{url('articles/add')}}">

  @csrf

  <div class="row">

    <div class="col-md-6">

      <div class="form-group">

        <input type="text" placeholder="Full Name" name="name" class="form-control">

      </div>

    </div>

    <div class="col-md-6">

      <div class="form-group">

        <input type="text" placeholder="Email" name="email" class="form-control">

      </div>

    </div>

    <div class="col-md-12"><br></div>

    <div class="col-md-6">

      <div class="form-group">

        <input type="text" placeholder="Mobile" name="mobile" class="form-control">

      </div>

    </div>

    <div class="col-md-6">

      <div class="form-group">

        <input type="text" placeholder="Full Address" name="full_address" class="form-control">

      </div>

    </div>

    <div class="col-md-12"><br></div>

    <div class="col-md-6">

      <div class="form-group">

      <button class="btn btn-primary">Submit</button>

      </div>

    </div>

  </div>

</form>

</div>

</body>

</html>



list.blade.php



<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Laravel Crud</title>

<link rel="stylesheet" type="text/css" href="{{asset('assets/css/bootstrap.min.css')}}">

<script type="text/javascript" src="{{asset('assets/js/bootstrap.min.js')}}"></script>

</head>

<body>

<nav class="navbar bg-dark bg-light">

  <div class="container-fluid">

    <a class="navbar-brand text-white">Welcome Laravel</a>

   

  </div>

</nav>

<div class="container">

<div><br></div>

<div class="col-md-12"><a href="{{url('articles/add')}}"><button class="btn btn-primary">Add</button></a></div>

<div><br></div>

  @if(Session::has('msg'))

  <div class="col-md-12">

    <div class="alert alert-success">

      {{session::get('msg')}}

    </div>

  </div>

  @endif

<table class="table table-bordered">

  <thead>

    <tr>

      <th scope="col">#</th>

      <th scope="col">Full Name</th>

      <th scope="col">Email</th>

      <th scope="col">Mobile</th>

      <th scope="col">Edit</th>

      <th scope="col">Delete</th>

    </tr>

  </thead>

  <tbody>

     @foreach($articles as $article)

           

      

    <tr>

      <th scope="row">{{ $article->id }}</th>

      <td>{{ $article->name }}</td>

      <td>{{ $article->email }}</td>

      <td>{{ $article->mobile }}</td>

      <td><a href="{{url('articles/update/'.$article->id)}}"><button class="btn btn-success">Edit</button></a></td>

      <td><a href="{{url('articles/remove/'.$article->id)}}"><button class="btn btn-danger">Remove</button></a></td>

    </tr>

      @endforeach

   

  </tbody>

</table>

</div>

</body>

</html>



update.blade.php



<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Laravel Crud</title>

<link rel="stylesheet" type="text/css" href="{{asset('assets/css/bootstrap.min.css')}}">

<script type="text/javascript" src="{{asset('assets/js/bootstrap.min.js')}}"></script>

</head>

<body>

<nav class="navbar bg-dark bg-light">

  <div class="container-fluid">

    <a class="navbar-brand text-white">Welcome Laravel</a>

   

  </div>

</nav>

<div class="container">

  <?php //print_r($articles);

/*foreach ($articles  as  $value) {

  //echo $name=$value->name;

}*/


  ?>

   

<div><br></div>

<form method="post" action="{{url('articles/update_data')}}">

  @csrf

  <div class="row">

    <div class="col-md-6">

      <div class="form-group">

         <input type="hidden" placeholder="Full Name" name="id" class="form-control" value="<?=$articles['id'];?>">

        <input type="text" placeholder="Full Name" name="name" class="form-control" value="<?=$articles['name'];?>">

      </div>

    </div>

    <div class="col-md-6">

      <div class="form-group">

        <input type="text" placeholder="Email" name="email" class="form-control" value="<?=$articles['email'];?>">

      </div>

    </div>

    <div class="col-md-12"><br></div>

    <div class="col-md-6">

      <div class="form-group">

        <input type="text" placeholder="Mobile" name="mobile" class="form-control" value="<?=$articles['mobile'];?>">

      </div>

    </div>

    <div class="col-md-6">

      <div class="form-group">

        <input type="text" placeholder="Full Address" name="full_address" class="form-control" value="<?=$articles['address'];?>">

      </div>

    </div>

    <div class="col-md-12"><br></div>

    <div class="col-md-6">

      <div class="form-group">

      <button class="btn btn-primary">Update</button>

      </div>

    </div>

  </div>

</form>

</div>

</body>

</html>









Database table

-- phpMyAdmin SQL Dump

-- version 5.1.0

-- https://www.phpmyadmin.net/

--

-- Host: 127.0.0.1

-- Generation Time: Aug 20, 2022 at 08:34 PM

-- Server version: 10.4.19-MariaDB

-- PHP Version: 7.3.28


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

START TRANSACTION;

SET time_zone = "+00:00";



/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8mb4 */;


--

-- Database: `laravel`

--


-- --------------------------------------------------------


--

-- Table structure for table `articles`

--


CREATE TABLE `articles` (

  `id` int(11) NOT NULL,

  `name` varchar(255) NOT NULL,

  `email` varchar(255) NOT NULL,

  `mobile` varchar(255) NOT NULL,

  `updated_at` varchar(255) NOT NULL,

  `created_at` varchar(255) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


--

-- Dumping data for table `articles`

--


INSERT INTO `articles` (`id`, `name`, `email`, `mobile`, `updated_at`, `created_at`) VALUES

(2, 'Ravindra Yadav', 'ravindrayadav170@yahoo.com', '8294066187', '2022-08-18 20:59:11', '2022-08-18 19:18:58'),

(8, 'Ravindra Yadav', 'ravindrayadav170@yahoo.com', '6299812434', '2022-08-18 20:54:02', '2022-08-18 20:54:02'),

(9, 'Ravindra Yadavv New', 'ravindrayadav170@yahoo.com', '7277924489', '2022-08-18 21:01:07', '2022-08-18 20:54:13'),

(10, 'Ravindra Yadav', 'divyag@outsourcingservicesusa.com', '8294066187', '2022-08-18 21:10:54', '2022-08-18 21:10:54'),

(11, 'Ravindra', 'mustafi@indorich.in', '6299812434', '2022-08-18 21:12:50', '2022-08-18 21:12:50');


--

-- Indexes for dumped tables

--


--

-- Indexes for table `articles`

--

ALTER TABLE `articles`

  ADD PRIMARY KEY (`id`);


--

-- AUTO_INCREMENT for dumped tables

--


--

-- AUTO_INCREMENT for table `articles`

--

ALTER TABLE `articles`

  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;

COMMIT;


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;





Comments

Popular posts from this blog

how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php

How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php

How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python