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(){
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);
}
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)
{
$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
{
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
.get('/api/setting-supplier/')
.get('/api/booking/'+ this.$route.params.id +'/po')
.then((response) => {
loading.close()
this.supplier_options = response.data
@@ -359,7 +359,7 @@
},
methods: {
submitChinaSlip(formName) {
uploadPo(formName) {
this.loading_btn = true
this.$refs[formName].validate((valid) => {
+56 -44
View File
@@ -4,9 +4,8 @@
<card :title="$t('settings')" class="settings-card">
<ul class="nav flex-column nav-pills">
<li v-for="tab in tabs" :key="tab.route" class="nav-item">
<router-link :to="{ name: tab.route }" class="nav-link" active-class="active">
<fa :icon="tab.icon" fixed-width/>
{{ tab.name }}
<router-link v-if="(role == tab.role)" :to="{ name: tab.route }" class="nav-link" active-class="active">
<fa :icon="tab.icon" fixed-width/> {{ tab.name }}
</router-link>
</li>
</ul>
@@ -22,50 +21,63 @@
</template>
<script>
export default {
middleware: 'auth',
import {
mapGetters
} from 'vuex'
export default {
middleware: 'auth',
computed: {
tabs () {
return [
{
icon: 'user',
name: this.$t('profile'),
route: 'settings.profile'
},
{
icon: 'lock',
name: this.$t('password'),
route: 'settings.password'
},
{
icon: 'user',
name: this.$t('Supplier'),
route: 'settings.admin-supplier'
},
{
icon: 'cog',
name: this.$t('Credit Setting'),
route: 'settings.admin-credit-setting'
},
{
icon: 'flag',
name: this.$t('CIEF China Bank'),
route: 'settings.admin-china-bank'
},
{
icon: 'building',
name: this.$t('Bank Setting'),
route: 'settings.admin-bank-setting'
},
]
computed: {
role() {
return this.$store.getters['auth/role']
},
tabs() {
return [{
icon: 'user',
name: this.$t('profile'),
route: 'settings.profile',
role: 'member'
},
{
icon: 'lock',
name: this.$t('password'),
route: 'settings.password',
role: 'member'
},
{
icon: 'user',
name: this.$t('Supplier'),
route: 'settings.admin-supplier',
role: 'admin'
},
{
icon: 'cog',
name: this.$t('Credit Setting'),
route: 'settings.admin-credit-setting',
role: 'admin'
},
{
icon: 'flag',
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>
<style>
.settings-card .card-body {
padding: 0;
}
</style>
.settings-card .card-body {
padding: 0;
}
</style>
+3
View File
@@ -103,6 +103,9 @@ Route::group(['middleware' => ['role:admin']], function() {
Route::post('/booking/{id}/upload-china-bankslip','ChinaBankSlipController@store');
Route::patch('/booking/{id}/update-china-bankslip','ChinaBankSlipController@update');
Route::get('/booking/{id}/po', 'BookingController@showPurchaseOrder');
});