PHP Classes

File: testapp/index.php

Recommend this page to a friend!
  Classes of Ar Gabid   Universal PHP Data Grid   testapp/index.php   Download  
File: testapp/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Universal PHP Data Grid
Display and process data to edit database records
Author: By
Last change: Update of testapp/index.php
Date: 4 years ago
Size: 1,727 bytes
 

Contents

Class file image Download
<?php
/**
 * @author GD Lab <dev.gdgrid@gmail.com>
 */

require_once 'init.php';

use
Seytar\Routing\Router;

use
Illuminate\Http\Request;

Router::bootstrap(function($ex)
{
   
header('Content-Type: text/html; charset=utf-8');
    echo
'404 - Page Not Found';
});

Route::get('/', function()
{
    include
'users.php';
});

Route::get('/delete/{id}', function($id)
{
    if (
$user = User::find($id))

       
$user->delete();

   
header('Location:/');

    exit;
});

Route::get('/create', function()
{
   
define('ROUTE', 'create');

   
$provider = new User;

    include
'form.php';
});

Route::get('/update/{id}', function($id)
{
   
define('ROUTE', 'update');

   
$provider = User::find($id);

    include
'form.php';
});

Route::post('/create', function()
{
   
define('ROUTE', 'create');

   
$provider = new User;

   
$request = Request::capture();

   
$validator = (new ValidatorFactory())->make($request->all(), $provider->rules());

   
$provider->loadData($request->all());

    if (
$validator->fails())
    {
       
$provider->setErrors($validator->messages()->toArray());
    }
    else
    {
       
$provider->save();

       
header('Location:/');

        exit;
    }

    include
'form.php';
});

Route::post('/update/{id}', function($id)
{
   
define('ROUTE', 'update');

   
$provider = User::find($id);

   
$request = Request::capture();

   
$validator = (new ValidatorFactory())->make($request->all(), $provider->rules());

   
$provider->loadData($request->all());

    if (
$validator->fails())
    {
       
$provider->setErrors($validator->messages()->toArray());
    }
    else
    {
       
$provider->save();

       
header('Location:/');

        exit;
    }

    include
'form.php';
});