rename book_id in po table to booking_id to perform ORM relantionship

added relationship between booking and po
updated settings shows for different role
added function to display po for admin
This commit is contained in:
Jack Goh
2018-06-28 10:06:26 +08:00
parent 9432cdaaad
commit 2b4ddadfcb
7 changed files with 110 additions and 46 deletions
+4
View File
@@ -43,5 +43,9 @@ class Booking extends Model
public function userBankSlip(){ public function userBankSlip(){
return $this->hasOne(UserBankSlip::class); return $this->hasOne(UserBankSlip::class);
} }
public function purchaseOrder(){
return $this->hasOne(PurchaseOrder::class);
}
} }
@@ -427,6 +427,13 @@ class BookingController extends Controller
return response()->json(['message'=>'Success'],200); return response()->json(['message'=>'Success'],200);
} }
public function showPurchaseOrder($id){
$booking = Booking::where('id',$id)->first();
$user_po = $booking->purchaseOrder()->first();
return response()->json(['po_path'=> $user_po],200);
}
public function delete(Booking $book_id) public function delete(Booking $book_id)
{ {
$booking = Booking::where('user_id', Auth::user())->where('id', $book_id)->firstOrFail(); $booking = Booking::where('user_id', Auth::user())->where('id', $book_id)->firstOrFail();
+5
View File
@@ -7,4 +7,9 @@ use Illuminate\Database\Eloquent\Model;
class PurchaseOrder extends Model class PurchaseOrder extends Model
{ {
protected $fillable = ['image_url','amount','booking_id']; protected $fillable = ['image_url','amount','booking_id'];
public function booking()
{
return $this->belongsTo(Booking::class);
}
} }
@@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RenameBookingForeignkeyInPoTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('purchase_orders', function($table)
{
$table->dropForeign('book_id');
$table->integer('booking_id')->unsigned();
$table->foreign('booking_id')->references('id')->on('bookings');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
@@ -345,7 +345,7 @@
}) })
axios axios
.get('/api/setting-supplier/') .get('/api/booking/'+ this.$route.params.id +'/po')
.then((response) => { .then((response) => {
loading.close() loading.close()
this.supplier_options = response.data this.supplier_options = response.data
@@ -359,7 +359,7 @@
}, },
methods: { methods: {
submitChinaSlip(formName) { uploadPo(formName) {
this.loading_btn = true this.loading_btn = true
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
+56 -44
View File
@@ -4,9 +4,8 @@
<card :title="$t('settings')" class="settings-card"> <card :title="$t('settings')" class="settings-card">
<ul class="nav flex-column nav-pills"> <ul class="nav flex-column nav-pills">
<li v-for="tab in tabs" :key="tab.route" class="nav-item"> <li v-for="tab in tabs" :key="tab.route" class="nav-item">
<router-link :to="{ name: tab.route }" class="nav-link" active-class="active"> <router-link v-if="(role == tab.role)" :to="{ name: tab.route }" class="nav-link" active-class="active">
<fa :icon="tab.icon" fixed-width/> <fa :icon="tab.icon" fixed-width/> {{ tab.name }}
{{ tab.name }}
</router-link> </router-link>
</li> </li>
</ul> </ul>
@@ -22,50 +21,63 @@
</template> </template>
<script> <script>
export default { import {
middleware: 'auth', mapGetters
} from 'vuex'
export default {
middleware: 'auth',
computed: { computed: {
tabs () { role() {
return [ return this.$store.getters['auth/role']
{ },
icon: 'user', tabs() {
name: this.$t('profile'), return [{
route: 'settings.profile' icon: 'user',
}, name: this.$t('profile'),
{ route: 'settings.profile',
icon: 'lock', role: 'member'
name: this.$t('password'), },
route: 'settings.password' {
}, icon: 'lock',
{ name: this.$t('password'),
icon: 'user', route: 'settings.password',
name: this.$t('Supplier'), role: 'member'
route: 'settings.admin-supplier' },
}, {
{ icon: 'user',
icon: 'cog', name: this.$t('Supplier'),
name: this.$t('Credit Setting'), route: 'settings.admin-supplier',
route: 'settings.admin-credit-setting' role: 'admin'
}, },
{ {
icon: 'flag', icon: 'cog',
name: this.$t('CIEF China Bank'), name: this.$t('Credit Setting'),
route: 'settings.admin-china-bank' route: 'settings.admin-credit-setting',
}, role: 'admin'
{ },
icon: 'building', {
name: this.$t('Bank Setting'), icon: 'flag',
route: 'settings.admin-bank-setting' name: this.$t('CIEF China Bank'),
}, route: 'settings.admin-china-bank',
] role: 'admin'
},
{
icon: 'building',
name: this.$t('Bank Setting'),
route: 'settings.admin-bank-setting',
role: 'admin'
},
]
}
} }
} }
}
</script> </script>
<style> <style>
.settings-card .card-body { .settings-card .card-body {
padding: 0; padding: 0;
} }
</style> </style>
+3
View File
@@ -103,6 +103,9 @@ Route::group(['middleware' => ['role:admin']], function() {
Route::post('/booking/{id}/upload-china-bankslip','ChinaBankSlipController@store'); Route::post('/booking/{id}/upload-china-bankslip','ChinaBankSlipController@store');
Route::patch('/booking/{id}/update-china-bankslip','ChinaBankSlipController@update'); Route::patch('/booking/{id}/update-china-bankslip','ChinaBankSlipController@update');
Route::get('/booking/{id}/po', 'BookingController@showPurchaseOrder');
}); });