GithubHelp home page GithubHelp logo

avinashn / ajax-crud-example-in-laravel Goto Github PK

View Code? Open in Web Editor NEW
72.0 72.0 63.0 496 KB

Example performing CRUD operations in laravel using ajax.

Home Page: https://justlaravel.com/ajax-crud-operations-laravel/

PHP 93.65% Vue 0.72% Shell 0.67% Blade 4.96%
ajax crud javascript laravel php

ajax-crud-example-in-laravel's People

Contributors

avinashn avatar caddydz avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ajax-crud-example-in-laravel's Issues

Parameter _token

Hi!
I do not understand, why you are passing the POST parameter "_token"? Where in the backend is it checked?

no migration file

to build this app from scratch u need a migration, before u can setup a database in the e.g. homestead.yaml and run the vagrant provision command on CLI

save the gist below under:
database/migrations/$timestamp$_create_ds_table.php

or run the artisan command on CLI:

vagrant@homestead:~/Code/ajax$ php artisan make:migration create_ds_table
Created Migration: 2016_08_25_101156_create_ds_table

and paste the code below

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::create('ds', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

xss

add html special chars to avoid xss:

ajax/app/Http/Controllers/IndexController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Data;
use Validator;
use Response;
use Illuminate\Support\Facades\Input;

class IndexController extends Controller {
    public function addItem(Request $request) {
        $rules = array (
                'name' => 'required'
        );
        $validator = Validator::make ( Input::all (), $rules );
        if ($validator->fails ())
            return Response::json ( array (

                    'errors' => $validator->getMessageBag ()->toArray ()
            ) );
        else {
            $data = new Data ();
            $data->name = htmlspecialchars($request->name);
            $data->save ();
            return response ()->json ( $data );
        }
    }
    public function readItems(Request $req) {
        $data = Data::all ();
        return view ( 'welcome' )->withData ( $data );
    }
    public function editItem(Request $req) {
        $data =Data::find ( $req->id );
        $data->name = htmlspecialchars($req->name);
        $data->save ();
        return response ()->json ( $data );
    }
    public function deleteItem(Request $req) {
        Data::find ( $req->id )->delete ();
        return response ()->json ();
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.