avinashn / ajax-crud-example-in-laravel Goto Github PK
View Code? Open in Web Editor NEWExample performing CRUD operations in laravel using ajax.
Home Page: https://justlaravel.com/ajax-crud-operations-laravel/
Example performing CRUD operations in laravel using ajax.
Home Page: https://justlaravel.com/ajax-crud-operations-laravel/
Hi!
I do not understand, why you are passing the POST parameter "_token"? Where in the backend is it checked?
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()
{
//
}
}
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 ();
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.