<repo_name>gagah1234/yogantara<file_sep>/routes/web.php
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$router->get('/', function () use ($router) {
    return $router->app->version();
});

$router->group(['middleware' => ['auth']], function ($router){

	//Cars CRUD
	$router->get('/cars', 'CarsController@index');
	$router->post('/cars', 'CarsController@store');
	$router->get('/cars/{id}', 'CarsController@show');
	$router->put('/cars/{id}', 'CarsController@update');
	$router->delete('/cars/{id}', 'CarsController@destroy');

	//Drivers CRUD
	$router->get('/drivers', 'DriversController@index');
	$router->post('/drivers', 'DriversController@store');
	$router->get('/drivers/{id}', 'DriversController@show');
	$router->put('/drivers/{id}', 'DriversController@update');
	$router->delete('/drivers/{id}', 'DriversController@destroy');

	//Borrowings CRUD
	$router->post('/borrowings', 'BorrowingsController@store');
	$router->get('/borrowings', 'BorrowingsController@index');
	$router->get('/borrowings/{id}', 'BorrowingsController@show');
	$router->delete('/borrowings/{id}', 'BorrowingsController@destroy');

	//Transactions CRUD
	$router->post('/transactions', 'TransactionsController@store');
	$router->get('/transactions', 'TransactionsController@index');
	$router->get('/transactions/{id}', 'TransactionsController@show');
});


$router->group(['prefix' => 'auth'], function() use ($router){
    $router->post('/register', 'AuthController@register');
    $router->post('/login', 'AuthController@login');
});

<file_sep>/app/Http/Controllers/BorrowingsController.php
<?php
namespace App\Http\Controllers;

use App\Models\Borrowing;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class BorrowingsController extends Controller
{
    public function index(Request $request)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $borrowing = Borrowing::OrderBy("id", "DESC")->paginate(10);

            if($acceptHeader === 'application/json')
            {
                return response()->json($borrowing, 200);
            } else {
                    $xml = new \SimpleXMLElement('<borrowings/>');

                    foreach ($borrowing->items('data') as $item)
                    {
                        $xmlItem = $xml->addChild('borrowing');

                        $xmlItem->addChild('id', $item->id);
                        $xmlItem->addChild('nama_peminjam', $item->nama_peminjam);
                        $xmlItem->addChild('jenis_kelamin', $item->jenis_kelamin);
                        $xmlItem->addChild('alamat', $item->alamat);
                        $xmlItem->addChild('created_at', $item->created_at);
                        $xmlItem->addChild('updated_at', $item->updated_at);
                    }
                    return $xml->asXML();   
                }
            }else{
                return response('Not Acceptable', 406);
        }
    }

	public function store(Request $request)
    {
        $acceptHeader = $request->header('Accept');
        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $input = $request->all();

            $validationRules = [
            'nama_peminjam'=> 'required',
            'jenis_kelamin' => 'required|',
            'alamat' => 'required|'
             ];
            $validator = \Validator::make($input, $validationRules);
            if($validator->fails()){
                return response()->json($validator->errors(), 400);
            }

            $borrowing = Borrowing::create($input);
            if($acceptHeader === 'application/json')
            {
                return response()->json($borrowing, 200);
            } else {
                $xml = new \SimpleXMLElement('<borrowings/>');
                    $xmlItem = $xml->addChild('borrowing');

                    $xmlItem->addChild('id', $item->id);
                    $xmlItem->addChild('nama_peminjam', $item->nama_peminjam);
                    $xmlItem->addChild('jenis_kelamin', $item->jenis_kelamin);
                    $xmlItem->addChild('alamat', $item->alamat);
                    $xmlItem->addChild('created_at', $item->created_at);
                    $xmlItem->addChild('updated_at', $item->updated_at);
                    
                    return $xml->asXML();   
            }
        }else{
            return response('Not Acceptable', 406);
        }
    }

    public function show(Request $request, $id)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $borrowing = Borrowing::find($id);
            if(!$borrowing){
                abort(404);
            }

            if($acceptHeader === 'application/json')
            {
                return response()->json($borrowing, 200);
            } else {
                $xml = new \SimpleXMLElement('<borrowings/>');

                    $xmlItem = $xml->addChild('borrowing');

                    $xmlItem->addChild('id', $borrowing->id);
                    $xmlItem->addChild('nama_peminjam', $borrowing->nama_peminjam);
                    $xmlItem->addChild('jenis_kelamin', $borrowing->jenis_kelamin);
                    $xmlItem->addChild('alamat', $borrowing->alamat);
                    $xmlItem->addChild('created_at', $borrowing->created_at);
                    $xmlItem->addChild('updated_at', $borrowing->updated_at);
                    
                    return $xml->asXML();   
            }
        }else{
            return response('Not Acceptable', 406);
        }
    }

    public function destroy(Request $request, $id)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $borrowing = Borrowing::find($id);
            if(!$borrowing){
                abort(404);
            }

            $borrowing->delete();

            if($acceptHeader === 'application/json')
            {
                $message = ['message' => 'deleted succesfully', 'borrowing_id' => $id];

                return response()->json($message, 200);
            } else {
                $xml = new \SimpleXMLElement('<borrowings/>');
                $xmlItem = $xml->addChild('borrowing');

                $xmlItem->addChild('id', $borrowing->id);
                $xmlItem->addChild('message' , 'deleted succesfully');

                return $xml->asXML();
            }

        }else{
                return response('Not Acceptable', 406);
            }
    }
}
?><file_sep>/app/Http/Controllers/DriversController.php
<?php
namespace App\Http\Controllers;

use App\Models\Driver;
use Illuminate\Http\Request;
use Illuminate\Http\Response;


class DriversController extends Controller
{
	public function index(Request $request)
	{
		$acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $driver = Driver::OrderBy("id", "DESC")->paginate(10);

            if($acceptHeader === 'application/json')
			{
                return response()->json($driver, 200);
			} else {
                    $xml = new \SimpleXMLElement('<drivers/>');

                    foreach ($driver->items('data') as $item)
                    {
                        $xmlItem = $xml->addChild('driver');

                        $xmlItem->addChild('id', $item->id);
                        $xmlItem->addChild('nama', $item->nama);
                        $xmlItem->addChild('jenis_kelamin', $item->jenis_kelamin);
                        $xmlItem->addChild('created_at', $item->created_at);
                        $xmlItem->addChild('updated_at', $item->updated_at);
                    }
                    return $xml->asXML();	
			    }
			}else{
				return response('Not Acceptable', 406);
        }
	}

    public function store(Request $request)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $input = $request->all();

            $validationRules = [
            'nama'=> 'required',
            'jenis_kelamin' => 'required|',
             ];

            $validator = \Validator::make($input, $validationRules);
            if($validator->fails()){
                return response()->json($validator->errors(), 400);
            }

            $driver = Driver::create($input);

            if($acceptHeader === 'application/json')
            {
                return response()->json($driver, 200);
            } else {
                $xml = new \SimpleXMLElement('<drivers/>');

                    $xmlItem = $xml->addChild('driver');

                    $xmlItem->addChild('id', $driver->id);
                    $xmlItem->addChild('nama', $driver->nama);
                    $xmlItem->addChild('jenis_kelamin', $driver->jenis_kelamin);
                    $xmlItem->addChild('created_at', $driver->created_at);
                    $xmlItem->addChild('updated_at', $driver->updated_at);
                    
                    return $xml->asXML();   
            }
        }else{
            return response('Not Acceptable', 406);
        }
    }

    public function show(Request $request, $id)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $driver = Driver::find($id);
            if(!$driver){
                abort(404);
            }

            if($acceptHeader === 'application/json')
            {
                return response()->json($driver, 200);
            } else {
                $xml = new \SimpleXMLElement('<drivers/>');

                    $xmlItem = $xml->addChild('driver');

                    $xmlItem->addChild('id', $driver->id);
                    $xmlItem->addChild('nama', $driver->nama);
                    $xmlItem->addChild('jenis_kelamin', $driver->jenis_kelamin);
                    $xmlItem->addChild('created_at', $driver->created_at);
                    $xmlItem->addChild('updated_at', $driver->updated_at);
                    
                    return $xml->asXML();   
            }
        }else{
            return response('Not Acceptable', 406);
        }
    }

    public function update(Request $request, $id)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $input = $request->all();

            $validationRules = [
            'nama'=> 'required',
            'jenis_kelamin' => 'required|',
             ];

            $validator = \Validator::make($input, $validationRules);
            if($validator->fails()){
                return response()->json($validator->errors(), 400);
            }
            
            $driver = Driver::find($id);
            if(!$driver){
                abort(404);
            }

            $driver->fill($input);
            $driver->save();

            if($acceptHeader === 'application/json')
            {
                return response()->json($driver, 200);
            } else {
                $xml = new \SimpleXMLElement('<drivers/>');

                    $xmlItem = $xml->addChild('driver');

                    $xmlItem->addChild('id', $driver->id);
                    $xmlItem->addChild('nama', $driver->nama);
                    $xmlItem->addChild('jenis_kelamin', $driver->jenis_kelamin);
                    $xmlItem->addChild('created_at', $driver->created_at);
                    $xmlItem->addChild('updated_at', $driver->updated_at);
                    
                    return $xml->asXML(); 
            }
        }else{
            return response('Not Acceptable', 406);
        }
    }

    public function destroy(Request $request, $id)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $driver = Driver::find($id);
            if(!$driver){
                abort(404);
            }

            $driver->delete();

            if($acceptHeader === 'application/json')
            {
                $message = ['message' => 'deleted succesfully', 'driver_id' => $id];

                return response()->json($message, 200);
            } else {
                $xml = new \SimpleXMLElement('<drivers/>');
                $xmlItem = $xml->addChild('driver');

                $xmlItem->addChild('id', $driver->id);
                $xmlItem->addChild('message' , 'deleted succesfully');

                return $xml->asXML();
            }

        }else{
                return response('Not Acceptable', 406);
            }
    }
}
?><file_sep>/app/Http/Controllers/TransactionsController.php
<?php
namespace App\Http\Controllers;

use App\Models\Transaction;
use Illuminate\Http\Request;
use Illuminate\Http\Response;


class TransactionsController extends Controller
{
    public function index(Request $request)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $transaction = Transaction::OrderBy("id", "DESC")->paginate(10);

            if($acceptHeader === 'application/json')
            {
                return response()->json($transaction, 200);
            } else {
                    $xml = new \SimpleXMLElement('<transactions/>');

                    foreach ($transaction->items('data') as $item)
                    {
                        $xmlItem = $xml->addChild('transaction');

                        $xmlItem->addChild('id', $item->id);
                        $xmlItem->addChild('tgl_transaksi', $item->tgl_transaksi);
                        $xmlItem->addChild('tgl_kembali', $item->tgl_kembali);
                        $xmlItem->addChild('jml_transaksi', $item->jml_transaksi);
                        $xmlItem->addChild('biaya', $item->biaya);
                        $xmlItem->addChild('id_pegawai', $item->biaya);
                        $xmlItem->addChild('id_mobil', $item->id_mobil);
                        $xmlItem->addChild('id_supir', $item->id_supir);
                        $xmlItem->addChild('id_peminjam', $item->id_peminjam);
                        $xmlItem->addChild('created_at', $item->created_at);
                        $xmlItem->addChild('updated_at', $item->updated_at);
                    }
                    return $xml->asXML();   
                }
            }else{
                return response('Not Acceptable', 406);
        }
    }

    public function store(Request $request)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $input = $request->all();

            $validationRules = [
            'tgl_transaksi'=> 'required',
            'tgl_kembali' => 'required|',
            'jml_transaksi' => 'required|',
            'biaya' => 'required|',
            'id_pegawai'=> 'required|exists:employees,id',
            'id_mobil'=> 'required|exists:cars,id',
            'id_supir'=> 'required|exists:drivers,id',
            'id_peminjaman'=> 'required|exists:borrowings,id',
             ];

            $validator = \Validator::make($input, $validationRules);
            if($validator->fails()){
                return response()->json($validator->errors(), 400);
            }

            $transaction = Transaction::create($input);

            if($acceptHeader === 'application/json')
            {
                return response()->json($transaction, 200);
            } else {
                $xml = new \SimpleXMLElement('<transactions/>');

                    $xmlItem = $xml->addChild('transaction');

                    $xmlItem->addChild('id', $transaction->id);
                    $xmlItem->addChild('tgl_transaksi', $transaction->tgl_transaksi);
                    $xmlItem->addChild('tgl_kembali', $transaction->tgl_kembali);
                    $xmlItem->addChild('jml_transaksi', $transaction->jml_transaksi);
                    $xmlItem->addChild('biaya', $transaction->biaya);
                    $xmlItem->addChild('id_pegawai', $transaction->biaya);
                    $xmlItem->addChild('id_mobil', $transaction->id_mobil);
                    $xmlItem->addChild('id_supir', $transaction->id_supir);
                    $xmlItem->addChild('id_peminjaman', $transaction->id_peminjaman);
                    $xmlItem->addChild('created_at', $transaction->created_at);
                    $xmlItem->addChild('updated_at', $transaction->updated_at);
                    
                    return $xml->asXML();   
            }
        }else{
            return response('Not Acceptable', 406);
        }
    }

    public function show(Request $request, $id)
    {
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $transaction = Transaction::find($id);
            if(!$transaction){
                abort(404);
            }

            if($acceptHeader === 'application/json')
            {
                return response()->json($transaction, 200);
            } else {
                $xml = new \SimpleXMLElement('<transactions/>');

                    $xmlItem = $xml->addChild('transaction');

                    $xmlItem->addChild('id', $transaction->id);
                    $xmlItem->addChild('tgl_transaksi', $transaction->tgl_transaksi);
                    $xmlItem->addChild('tgl_kembali', $transaction->tgl_kembali);
                    $xmlItem->addChild('jml_transaksi', $transaction->jml_transaksi);
                    $xmlItem->addChild('biaya', $transaction->biaya);
                    $xmlItem->addChild('id_pegawai', $transaction->biaya);
                    $xmlItem->addChild('id_mobil', $transaction->id_mobil);
                    $xmlItem->addChild('id_supir', $transaction->id_supir);
                    $xmlItem->addChild('id_peminjaman', $transaction->id_peminjaman);
                    $xmlItem->addChild('created_at', $transaction->created_at);
                    $xmlItem->addChild('updated_at', $transaction->updated_at);
                    
                    return $xml->asXML();   
            }
        }else{
            return response('Not Acceptable', 406);
        }
    }
}
?><file_sep>/app/Http/Controllers/CarsController.php
<?php
namespace App\Http\Controllers;

use App\Models\Car;
use Illuminate\Http\Request;
use Illuminate\Http\Response;


class CarsController extends Controller
{
	public function index(Request $request)
	{
		$acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $car = Car::OrderBy("id", "DESC")->paginate(10);

            if($acceptHeader === 'application/json')
			{
                return response()->json($car, 200);
			} else {
                    $xml = new \SimpleXMLElement('<cars/>');

                    foreach ($car->items('data') as $item)
                    {
                        $xmlItem = $xml->addChild('car');

                        $xmlItem->addChild('id', $item->id);
                        $xmlItem->addChild('jenis', $item->jenis);
                        $xmlItem->addChild('kapasitas', $item->kapasitas);
                        $xmlItem->addChild('nopol', $item->nopol);
                        $xmlItem->addChild('id_pegawai', $item->harga);
                        $xmlItem->addChild('created_at', $item->created_at);
                        $xmlItem->addChild('updated_at', $item->updated_at);
                    }
                    return $xml->asXML();	
			    }
			}else{
				return response('Not Acceptable', 406);
        }
	}

	public function store(Request $request)
	{
		$acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $input = $request->all();

            $validationRules = [
            'jenis'=> 'required',
            'kapasitas' => 'required|',
            'nopol' => 'required|',
            'id_pegawai' => 'required|exists:employees,id',
	         ];

	        $validator = \Validator::make($input, $validationRules);
	        if($validator->fails()){
	            return response()->json($validator->errors(), 400);
	        }

            $car = Car::create($input);

            if($acceptHeader === 'application/json')
			{
				return response()->json($car, 200);
			} else {
                $xml = new \SimpleXMLElement('<cars/>');

                    $xmlItem = $xml->addChild('car');

                    $xmlItem->addChild('id', $car->id);
                    $xmlItem->addChild('jenis', $car->jenis);
                    $xmlItem->addChild('kapasitas', $car->kapasitas);
                    $xmlItem->addChild('nopol', $car->nopol);
                    $xmlItem->addChild('id_pegawai', $car->id_pegawai);
                    $xmlItem->addChild('created_at', $car->created_at);
                    $xmlItem->addChild('updated_at', $car->updated_at);
                    
                    return $xml->asXML();	
			}
        }else{
            return response('Not Acceptable', 406);
        }
	}

	public function show(Request $request, $id)
	{
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $car = Car::find($id);
	        if(!$car){
	            abort(404);
	        }

            if($acceptHeader === 'application/json')
			{
				return response()->json($car, 200);
			} else {
                $xml = new \SimpleXMLElement('<cars/>');

                    $xmlItem = $xml->addChild('car');

                    $xmlItem->addChild('id', $car->id);
                    $xmlItem->addChild('jenis', $car->jenis);
                    $xmlItem->addChild('kapasitas', $car->kapasitas);
                    $xmlItem->addChild('nopol', $car->nopol);
                    $xmlItem->addChild('id_pegawai', $car->id_pegawai);
                    $xmlItem->addChild('created_at', $car->created_at);
                    $xmlItem->addChild('updated_at', $car->updated_at);
                    
                    return $xml->asXML();	
			}
        }else{
            return response('Not Acceptable', 406);
        }
	}

	public function update(Request $request, $id)
	{
        $acceptHeader = $request->header('Accept');

        if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
        {
            $input = $request->all();

            $validationRules = [
            'jenis'=> 'required',
            'kapasitas' => 'required|',
            'nopol' => 'required|',
            'id_pegawai' => 'required|exists:employees,id',
	         ];

	        $validator = \Validator::make($input, $validationRules);
	        if($validator->fails()){
	            return response()->json($validator->errors(), 400);
	        }
	        
            $car = Car::find($id);
	        if(!$car){
	            abort(404);
	        }
            $car = Car::create($input);

            $car->fill($input);
        	$car->save();

            if($acceptHeader === 'application/json')
			{
				return response()->json($car, 200);
			} else {
                $xml = new \SimpleXMLElement('<cars/>');

                    $xmlItem = $xml->addChild('car');

                    $xmlItem->addChild('id', $car->id);
                    $xmlItem->addChild('jenis', $car->jenis);
                    $xmlItem->addChild('kapasitas', $car->kapasitas);
                    $xmlItem->addChild('nopol', $car->nopol);
                    $xmlItem->addChild('id_pegawai', $car->id_pegawai);
                    $xmlItem->addChild('created_at', $car->created_at);
                    $xmlItem->addChild('updated_at', $car->updated_at);
                    
                    return $xml->asXML();	
			}
        }else{
            return response('Not Acceptable', 406);
        }
	}

	public function destroy(Request $request, $id)
	{
        $acceptHeader = $request->header('Accept');

		if($acceptHeader === 'application/json' || $acceptHeader === 'application/xml')
		{
			$car = Car::find($id);
	        if(!$car){
	            abort(404);
	        }

	        $car->delete();

			if($acceptHeader === 'application/json')
			{
				$message = ['message' => 'deleted succesfully', 'car_id' => $id];

        		return response()->json($message, 200);
			} else {
				$xml = new \SimpleXMLElement('<Cars/>');
				$xmlItem = $xml->addChild('car');

				$xmlItem->addChild('id', $car->id);
				$xmlItem->addChild('message' , 'deleted succesfully');

				return $xml->asXML();
			}

		}else{
				return response('Not Acceptable', 406);
			}
	}
}
?><file_sep>/app/Models/Car.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Car extends Model
{
	protected $fillable = [
		'jenis', 'kapasitas', 'nopol', 'id_pegawai',
	];

	public $timestamps = true;
}
?><file_sep>/app/Models/Transaction.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Transaction extends Model
{
	protected $fillable = [
		'tgl_transaksi', 'tgl_kembali', 'jml_transaksi', 'biaya', 'id_pegawai', 'id_mobil', 'id_supir', 'id_peminjaman',
	];

	public $timestamps = true;
}
?><file_sep>/app/Models/Borrowing.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Borrowing extends Model
{
	protected $fillable = [
		'nama_peminjam', 'jenis_kelamin', 'alamat',
	];

	public $timestamps = true;
}
?>