model changes for accepted bids and contracts

This commit is contained in:
2019-04-26 02:56:34 -05:00
parent 791681034c
commit a977f36377
4 changed files with 23 additions and 10 deletions

View File

@@ -28,12 +28,12 @@ class ContractAdminController extends Controller
$contracts = Contract::where(['date', '>=', $today])->get(); $contracts = Contract::where(['date', '>=', $today])->get();
return view('contracts/admin/contractpanel'); return view('contracts.admin.contractpanel');
} }
public function displayNewContract() { public function displayNewContract() {
return view('contracts/admin/newcontract'); return view('contracts.admin.newcontract');
} }
public function storeNewContract() { public function storeNewContract() {
@@ -42,6 +42,11 @@ class ContractAdminController extends Controller
} }
public function storeAcceptContract(Request $request) { public function storeAcceptContract(Request $request) {
$this->validate($request, [
'contract_id',
'character_id',
'bid_amount',
]);
return redirect('/contracts/admin/display'); return redirect('/contracts/admin/display');
} }

View File

@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class AcceptedBid extends Model class AcceptedBid extends Model
{ {
// Table Name // Table Name
public $table = 'accepted_bid'; public $table = 'accepted_bids';
//Timestamps //Timestamps
public $timestamps = true; public $timestamps = true;
@@ -20,6 +20,10 @@ class AcceptedBid extends Model
protected $fillable = [ protected $fillable = [
'contract_id', 'contract_id',
'bid_id', 'bid_id',
'amount', 'bid_amount',
]; ];
public function Contract() {
return $this->belongsTo(Contract::class);
}
} }

View File

@@ -23,9 +23,13 @@ class Contract extends Model
'body', 'body',
]; ];
protected $guarded = []; //One-to-Many relationship for the bids on a contract
public function Bids() { public function Bids() {
return $this->hasMany('App\Models\Contracts\Bid', 'contract_id', 'id'); return $this->hasMany('App\Models\Contracts\Bid', 'contract_id', 'id');
} }
//One-to-One relationship for the accepted bid.
public function AcceptedBid() {
return $this->hasOne('App\Models\Contracts\AcceptedBid', 'contract_id', 'id');
}
} }

View File

@@ -36,12 +36,12 @@ class CreateContractsTable extends Migration
}); });
} }
if(!Schema::hasTable('accepted_bid')) { if(!Schema::hasTable('accepted_bids')) {
Schema::create('accepted_bid', function(Blueprint $table) { Schema::create('accepted_bids', function(Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('contract_id'); $table->integer('contract_id');
$table->integer('bid_id'); $table->integer('bid_id');
$table->decimal('amount'); $table->decimal('bid_amount');
$table->timestamps(); $table->timestamps();
}); });
} }
@@ -56,6 +56,6 @@ class CreateContractsTable extends Migration
{ {
Schema::dropIfExists('contracts'); Schema::dropIfExists('contracts');
Schema::dropIfExists('contract_bids'); Schema::dropIfExists('contract_bids');
Schema::dropIfExists('contract_bid_accepted'); Schema::dropIfExists('accepted_bids');
} }
} }