This commit is contained in:
Azfar Arsyad
2022-01-20 15:47:01 +08:00
parent 3c20c03ab9
commit 043925ea9b
7 changed files with 184 additions and 20 deletions
@@ -13,7 +13,6 @@ use Illuminate\Support\Facades\Validator;
class AuthController extends Controller
{
public function register(Request $request) {
$validator = Validator::make($request->all(), [
'name' => 'required|string',
'username' => 'required|string|unique:users',
@@ -23,17 +22,19 @@ class AuthController extends Controller
'register_agree' => 'required|integer'
]);
$errors = [
'success' => "error",
'message' => $validator->errors()
];
if ($validator->fails()) {
$errors = [
'success' => "error",
'message' => $validator->errors()
];
return response($errors, 201);
}
// Retrieve the validated input...
$fields = $validator->validated();
$currentdate = Carbon::now();
$currentdate = $currentdate->toDateString();
@@ -46,16 +47,17 @@ class AuthController extends Controller
$user->register_agree = $fields['register_agree'];
$user->t_daftar = $currentdate;
$user->user_type = 2; //type 2 = pembida
$images = $request->images;
if($user->save())
{
$images = $request->images;
foreach($images as $img)
{
$file = new File;
$file->user_id = $user->id;
$file->file_type = $img->file_type;
$file->filename = $img->filename;
$file->file_type = $img['file_type'];
$file->filename = $img['filename'];
$file->save();
}
}
@@ -66,12 +68,7 @@ class AuthController extends Controller
'user' => $user,
'token' => $token
];
// return back()
// ->with('success','You have successfully upload image.')
// ->with('image',$imageName);
return response($response, 201);
}
+141
View File
@@ -0,0 +1,141 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use PDF;
use App\Models\Cawangan;
use App\Models\JenisEmas;
use App\Models\JenisKarat;
use App\Models\Lelong;
use App\Models\CawanganLelong;
use App\Models\LelongBid;
use App\Models\LelongBidMarhun;
use App\Models\LelKarat;
use App\Models\Cart;
use Carbon\Carbon;
class CartController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getCart($userid)
{
$carts = Cart::where('user_id','=', $userid)->get();
foreach($carts as $cart)
{
$arraycart = [];
$lelongbid = LelongBid::where('id',$cart->lelongbid_id)->first();
$marhun = LelongBidMarhun::where('lelongbid_id','=',$lelongbid->id)->get();
$lelongbid->marhun = $marhun;
$cart->lelongbid = $lelongbid;
}
if(sizeof($carts)!=0)
{
return response()->json([
'success' => true,
'carts' => $carts
]);
}
else
{
return response()->json([
'success' => false,
'message' => 'No Data',
], 401);
}
}
public function addToCart(Request $request)
{
$item = new Cart;
$item->user_id = $request->user_id;
$item->lelongbid_id = $request->lelongbid_id;
$item->hargabida = $request->hargabida;
if($item->save())
{
$carts = Cart::where('user_id','=', $request->user_id)->get();
foreach($carts as $cart)
{
$arraycart = [];
$lelongbid = LelongBid::where('id',$cart->lelongbid_id)->first();
$marhun = LelongBidMarhun::where('lelongbid_id','=',$lelongbid->id)->get();
$lelongbid->marhun = $marhun;
$cart->lelongbid = $lelongbid;
}
return response()->json([
'success' => true,
'carts' => $carts
]);
}
else
{
return response()->json([
'success' => false,
'message' => 'Error! Cannot save.',
], 401);
}
}
public function updateItem (Request $request)
{
$cart = Cart::where('id','=',$request->id)->first();
$cart->hargabida = $request->hargabida;
if($cart->save())
{
return response()->json([
'success' => true,
'cart' => $cart
]);
}
else
{
return response()->json([
'success' => false,
'message' => 'Error! Cannot save.',
], 401);
}
}
public function deleteCart($id)
{
$cart = Cart::where('id','=',$id)->first();
if($cart->delete())
{
return response()->json([
'success' => true,
'message' => 'Delete Success'
]);
}
else
{
return response()->json([
'success' => false,
'message' => 'Error! Cannot save.',
], 401);
}
}
}
+2 -3
View File
@@ -56,7 +56,6 @@ class SimulasiController extends Controller
$t_lelong = Carbon::parse($request->tarikh_lelong);
$bulan = round($request->jbg,0);
$jbgadai = ($t_lelong->subMonths($bulan))->toDateString();
// dd($jbgadai);
$surat = Gadai::where('t_gadai','<=',$jbgadai)
->where('sttebus','=',0)
@@ -114,7 +113,7 @@ class SimulasiController extends Controller
$simulasibid->caw_id = $caw->id;
$simulasibid->kodcaw = $data->kodcaw;
$simulasibid->norujukan = $data->norujukan;
$simulasibid->t_lelong = $t_lelong;
$simulasibid->t_lelong = $request->tarikh_lelong;
$simulasibid->hargaasas = 0.00;
$simulasibid->hargajual = 0.00;
$simulasibid->jbg = $data->jbg;
@@ -200,7 +199,7 @@ class SimulasiController extends Controller
$simulasibid->caw_id = $caw->id;
$simulasibid->kodcaw = $data->kodcaw;
$simulasibid->norujukan = $data->norujukan;
$simulasibid->t_lelong = $t_lelong;
$simulasibid->t_lelong = $request->tarikh_lelong;
$simulasibid->hargaasas = 0.00;
$simulasibid->hargajual = 0.00;
$simulasibid->jbg = $data->jbg;
+9
View File
@@ -8,4 +8,13 @@ use Illuminate\Database\Eloquent\Model;
class Cart extends Model
{
use HasFactory;
protected $table = 'carts';
protected $fillable = [
'user_id',
'lelongbid_id',
'hargabida'
];
}
@@ -17,7 +17,7 @@ class CreateFileTable extends Migration
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->unsigned();
$table->string('file_type');
$table->string('filename');
$table->binary('filename');
$table->datetime('deleted_at')->nullable();
$table->integer('deleted_by')->nullable();
$table->timestamps();
@@ -14,8 +14,19 @@ class CreateCartsTable extends Migration
public function up()
{
Schema::create('carts', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->unsigned();
$table->unsignedBigInteger('lelongbid_id')->unsigned();
$table->decimal('hargabida', $precision = 9, $scale = 2);
$table->timestamps();
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('lelongbid_id')
->references('id')->on('lelongbid')
->onDelete('cascade');
});
}
+8 -1
View File
@@ -4,6 +4,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthMobile\AuthController;
use App\Http\Controllers\AuthMobile\UserController;
use App\Http\Controllers\CartController;
/*
|--------------------------------------------------------------------------
@@ -20,12 +21,18 @@ use App\Http\Controllers\AuthMobile\UserController;
Route::post('/register', [AuthController::class, 'register']);
Route::post('/login', [AuthController::class, 'login']);
Route::post('/forgotpassword', [ResetPassword::class, 'forgotpassword']);
Route::post('/addToCart', [CartController::class, 'addToCart']);
Route::get('/cart/{userid}', [CartController::class, 'getCart']);
//Protected routes
Route::group(['middleware' => ['auth:sanctum']], function () {
Route::post('/logout', [AuthController::class, 'logout']);
Route::get('/user/profile/{nokp}', [UserController::class, 'getProfileUser']);
Route::post('/updateItem', [CartController::class, 'updateItem']);
Route::get('/deleteItem/{id}', [CartController::class, 'deleteCart']);
});
// Route::post('/login', function (Request $request) {