Commit 32b62e39 authored by arifrm's avatar arifrm
Browse files

Complete-profile

parent ee84066e
Showing with 1271 additions and 438 deletions
+1271 -438
......@@ -12,5 +12,4 @@ npm-debug.log
yarn-error.log
/.idea
/.vscode
node_modules
composer.lock
\ No newline at end of file
node_modules
\ No newline at end of file
......@@ -48,7 +48,6 @@ public function handleGoogleCallback(Request $request)
return redirect()->intended('cashier/dashboard');
break;
}
} else {
try {
......@@ -74,14 +73,13 @@ public function handleGoogleCallback(Request $request)
Auth::login($newUser);
return redirect()->intended('owner/dashboard');
return redirect()->intended(route('owner.complete-profile'));
} catch (Exception $th) {
DB::rollBack();
Log::error("Error when store data to databases in user registration with socialite, the error is: " . $th);
dd($th->getMessage());
}
}
} catch (Exception $e) {
dd($e->getMessage());
}
......@@ -92,4 +90,4 @@ public function logout()
Auth::logout();
return redirect('login');
}
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers\Owner;
use App\Http\Controllers\Controller;
use App\Http\Requests\Owner\CompleteProfileValidate;
use App\Models\District;
use App\Models\Gender;
use App\Models\Province;
use App\Models\Regency;
use App\Models\ShopModel;
use App\Models\UserProfileModel;
use App\Models\Village;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
class CompleteProfileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$provinces = Province::all();
$userId = Auth::user()->id;
$userProfile = UserProfileModel::where('user_id', $userId)->first();
return view('page.owner.fill-profile.index', [
'provinces' => $provinces,
'userProfile' => $userProfile,
]);
}
public function getRegencies(Request $request)
{
$regencies = Regency::where('province_id', $request->id_province)->get();
echo "<option value='null' selected disabled>-- Select --</option>";
foreach ($regencies as $regency) {
echo "<option value='$regency->id'>$regency->name</option>";
}
}
public function getDistrict(Request $request)
{
$districts = District::where('regency_id', $request->id_regency)->get();
echo "<option value='null' selected disabled>-- Select --</option>";
foreach ($districts as $district) {
echo "<option value='$district->id'>$district->name</option>";
}
}
public function getVillage(Request $request)
{
$villages = Village::where('district_id', $request->id_district)->get();
echo "<option value='null' selected disabled>-- Select --</option>";
foreach ($villages as $village) {
echo "<option value='$village->id'>$village->name</option>";
}
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(CompleteProfileValidate $request, $idEncrypt)
{
$provinceName = Province::where('id', $request->provinceBusiness)->first()->name;
$regencyName = Regency::where('id', $request->regencyBusiness)->first()->name;
$districtName = District::where('id', $request->districtBusiness)->first()->name;
$villageName = Village::where('id', $request->villageBusiness)->first()->name;
$id = Crypt::decrypt($idEncrypt);
// dd($request, Crypt::decrypt($idEncrypt), $provinceName, $regencyName, $districtName, $villageName);
try {
$userProfile = UserProfileModel::findOrFail($id);
DB::beginTransaction();
$userProfile->update([
'first_name' => $request->firstName,
'last_name' => $request->lastName,
'nickname' => $request->nickName,
'gender' => $request->gender,
'phone' => $request->phone,
'birthdate' => $request->birthDate,
'address' => $request->address,
]);
ShopModel::create([
'name' => $request->nameBusiness,
'description' => $request->descriptionBusiness,
'email' => $request->emailBusiness,
'user_id' => $userProfile->user_id,
'contact' => $request->contactBusiness,
'province' => $provinceName,
'regency' => $regencyName,
'district' => $districtName,
'village' => $villageName,
'address' => $request->addressBusiness,
]);
// dd($userProfile, $update);
DB::commit();
} catch (\Throwable $th) {
//throw $th;
DB::rollBack();
dd($th);
return back();
}
return redirect(route('owner.dashboard'))->with('success', 'Success complete your profile');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
\ No newline at end of file
......@@ -143,4 +143,4 @@ public function destroy($id)
return response()->json(['status' => 'error']);
}
}
}
\ No newline at end of file
}
<?php
namespace App\Http\Requests\Owner;
use Illuminate\Foundation\Http\FormRequest;
class CompleteProfileValidate extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'firstName' => 'required',
'lastName' => 'required',
'nickName' => 'required',
'gender' => 'required',
'phone' => 'required',
'birthDate' => 'required|date',
'address' => '',
'nameBusiness' => 'required',
'emailBusiness' => 'required|email:dns',
'contactBusiness' => 'required|numeric|min_digits:8',
'provinceBusiness' => 'required',
'regencyBusiness' => 'required',
'districtBusiness' => 'required',
'villageBusiness' => 'required',
'addressBusiness' => '',
];
}
}
\ No newline at end of file
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
namespace App\Models;
use AzisHapidin\IndoRegion\Traits\DistrictTrait;
use Illuminate\Database\Eloquent\Model;
use App\Models\Regency;
use App\Models\Village;
/**
* District Model.
*/
class District extends Model
{
use DistrictTrait;
/**
* Table name.
*
* @var string
*/
protected $table = 'districts';
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'regency_id'
];
/**
* District belongs to Regency.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function regency()
{
return $this->belongsTo(Regency::class);
}
/**
* District has many villages.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function villages()
{
return $this->hasMany(Village::class);
}
}
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
namespace App\Models;
use AzisHapidin\IndoRegion\Traits\ProvinceTrait;
use Illuminate\Database\Eloquent\Model;
/**
* Province Model.
*/
class Province extends Model
{
use ProvinceTrait;
/**
* Table name.
*
* @var string
*/
protected $table = 'provinces';
/**
* Province has many regencies.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function regencies()
{
return $this->hasMany(Regency::class);
}
}
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
namespace App\Models;
use AzisHapidin\IndoRegion\Traits\RegencyTrait;
use Illuminate\Database\Eloquent\Model;
/**
* Regency Model.
*/
class Regency extends Model
{
use RegencyTrait;
/**
* Table name.
*
* @var string
*/
protected $table = 'regencies';
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'province_id'
];
/**
* Regency belongs to Province.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function province()
{
return $this->belongsTo(Province::class);
}
/**
* Regency has many districts.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function districts()
{
return $this->hasMany(District::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ShopModel extends Model
{
use HasFactory;
protected $table = 'shops';
protected $guarded = ['id'];
public function user()
{
return $this->belongsTo(User::class);
}
}
\ No newline at end of file
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
namespace App\Models;
use AzisHapidin\IndoRegion\Traits\VillageTrait;
use Illuminate\Database\Eloquent\Model;
use App\Models\District;
/**
* Village Model.
*/
class Village extends Model
{
use VillageTrait;
/**
* Table name.
*
* @var string
*/
protected $table = 'villages';
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'district_id'
];
/**
* Village belongs to District.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function district()
{
return $this->belongsTo(District::class);
}
}
......@@ -2,10 +2,14 @@
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^8.0.2",
"azishapidin/indoregion": "^3.0",
"barryvdh/laravel-debugbar": "^3.8",
"barryvdh/laravel-dompdf": "^2.0",
"google/apiclient": "^2.13",
......@@ -16,8 +20,8 @@
"laravel/socialite": "^5.6",
"laravel/tinker": "^2.7",
"league/flysystem-aws-s3-v3": "^3.13",
"livewire/livewire": "^2.12",
"maatwebsite/excel": "3.1.48"
"livewire/livewire": "^2.12"
},
"require-dev": {
"fakerphp/faker": "^1.21",
......
This diff is collapsed.
......@@ -187,6 +187,7 @@
*/
Intervention\Image\ImageServiceProvider::class,
Maatwebsite\Excel\ExcelServiceProvider::class,
AzisHapidin\IndoRegion\IndoRegionServiceProvider::class,
/*
* Application Service Providers...
......
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProvincesTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('provinces', function(Blueprint $table){
$table->char('id', 2)->index();
$table->string('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('provinces');
}
}
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRegenciesTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('regencies', function(Blueprint $table){
$table->char('id', 4)->index();
$table->char('province_id', 2);
$table->string('name', 50);
$table->foreign('province_id')
->references('id')
->on('provinces')
->onUpdate('cascade')->onDelete('restrict');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('regencies');
}
}
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDistrictsTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('districts', function(Blueprint $table){
$table->char('id', 7)->index();
$table->char('regency_id', 4);
$table->string('name', 50);
$table->foreign('regency_id')
->references('id')
->on('regencies')
->onUpdate('cascade')->onDelete('restrict');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('districts');
}
}
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateVillagesTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('villages', function(Blueprint $table){
$table->char('id', 10)->index();
$table->char('district_id', 7);
$table->string('name', 50);
$table->foreign('district_id')
->references('id')
->on('districts')
->onUpdate('cascade')->onDelete('restrict');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('villages');
}
}
......@@ -28,7 +28,7 @@ public function up()
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')
->cascadeOnDelete()->cascadeOnUpdate();
->cascadeOnDelete()->cascadeOnUpdate();
});
}
......@@ -41,4 +41,4 @@ public function down()
{
Schema::dropIfExists('user_profile');
}
};
};
\ No newline at end of file
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('shops', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->unsignedBigInteger('user_id');
$table->string('email');
$table->string('contact');
$table->string('province');
$table->string('regency');
$table->string('district');
$table->string('village');
$table->string('address')->nullable();
$table->boolean('isActive')->default(true);
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')
->cascadeOnDelete()->cascadeOnUpdate();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('shops');
}
};
\ No newline at end of file
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Azis Hapidin <azishapidin.com | azishapidin@gmail.com>
*
*/
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use AzisHapidin\IndoRegion\RawDataGetter;
use Illuminate\Support\Facades\DB;
class IndoRegionDistrictSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @deprecated
*
* @return void
*/
public function run()
{
// Get Data
$districts = RawDataGetter::getDistricts();
// Insert Data to Database
DB::table('districts')->insert($districts);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment