Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Last active May 31, 2020 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/528394b6447092fdb369492524b4fd2e to your computer and use it in GitHub Desktop.
Save uno-de-piera/528394b6447092fdb369492524b4fd2e to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Support\Facades\Route;
use Yajra\DataTables\Facades\DataTables;
/*
|--------------------------------------------------------------------------
| 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!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::group(['prefix' => 'users', 'middleware' => 'auth'], function()
{
Route::get('/:id', function($id)
{
echo $id;
})->name('users.detail');
Route::get('/', function() {
$users = \App\User::all();
return view('users.index', compact('users'));
})->name('users.index');
Route::get('/datatables', function() {
return view('users.datatables');
})->name('users.datatables');
Route::get('/json_data', function() {
$model = \App\User::query();
return Datatables::eloquent($model)
->addColumn('actions', function ($user) {
return '
<a href="' . route('users.destroy') . '" data-id="' . $user['id'] . '" data-remove="true" class="btn btn-danger"><i class="ion ion-trash-a"></i> Destroy </a>
';
})
->rawColumns(['actions'])
->make(true);
})->name('users.json_data');
Route::delete('/', function(\Illuminate\Http\Request $request)
{
if($request->ajax())
{
$id = $request->input('id');
\Illuminate\Support\Facades\Log::info($id);
\App\User::destroy($id);
return response()->json(['response' => 'user removed']);
}
abort(401);
})->name('users.destroy');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment