small fixes

shift-build-2464
Nadim Salloum 2021-06-05 20:42:36 +03:00
parent db4f29d0f7
commit 79ac1dcda3
6 changed files with 14 additions and 5 deletions

View File

@ -132,6 +132,7 @@ class ContractController extends Controller
{ {
$contract = Contract::create( $contract = Contract::create(
$request->validate([ $request->validate([
'type' => ['required'],
'date' => ['required', 'date'], 'date' => ['required', 'date'],
'price' => ['required', 'integer'], 'price' => ['required', 'integer'],
'car_id' => ['required', 'exists:App\Models\Car,id'], 'car_id' => ['required', 'exists:App\Models\Car,id'],

View File

@ -58,12 +58,12 @@ class Contract extends Model
public function contact() public function contact()
{ {
return $this->belongsTo(Contact::class); return $this->belongsTo(Contact::class)->withTrashed();
} }
public function car() public function car()
{ {
return $this->belongsTo(Car::class); return $this->belongsTo(Car::class)->withTrashed();
} }
public function scopeThisYear($query) public function scopeThisYear($query)

View File

@ -3,6 +3,7 @@
namespace App\Providers; namespace App\Providers;
use App\Models\Car; use App\Models\Car;
use App\Models\Contact;
use App\Models\Contract; use App\Models\Contract;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@ -56,6 +57,13 @@ class RouteServiceProvider extends ServiceProvider
return Car::find($value); return Car::find($value);
}); });
Route::bind('contact', function ($value) {
if (in_array(Route::currentRouteName(), ['contacts.show', 'contacts.restore'])) {
return Contact::withTrashed()->find($value);
}
return Contact::find($value);
});
Route::bind('contract', function ($value) { Route::bind('contract', function ($value) {
if (in_array(Route::currentRouteName(), ['contracts.show', 'contracts.restore'])) { if (in_array(Route::currentRouteName(), ['contracts.show', 'contracts.restore'])) {
return Contract::withTrashed()->find($value); return Contract::withTrashed()->find($value);

2
public/js/app.js vendored
View File

@ -19528,7 +19528,7 @@ __webpack_require__.r(__webpack_exports__);
id: null, id: null,
date: null, date: null,
price: null, price: null,
type: this.type, type: this.type == "SellContract" ? 0 : 1,
insurance_type: '0', insurance_type: '0',
car_id: this.car.id, car_id: this.car.id,
contact_id: this.contact.id contact_id: this.contact.id

View File

@ -89,7 +89,7 @@ export default {
id: null, id: null,
date: null, date: null,
price: null, price: null,
type: this.type, type: this.type == "SellContract" ? 0 : 1,
insurance_type: '0', insurance_type: '0',
car_id: this.car.id, car_id: this.car.id,
contact_id: this.contact.id, contact_id: this.contact.id,

View File

@ -69,7 +69,7 @@ Route::put('contacts/{contact}', [ContactController::class, 'update'])
->name('contacts.update') ->name('contacts.update')
->middleware(['auth:sanctum', 'verified']); ->middleware(['auth:sanctum', 'verified']);
Route::delete('contacts/{contact}', [ContactController::class, 'destroy']) Route::get('contacts/{contact}/delete', [ContactController::class, 'destroy'])
->name('contacts.destroy') ->name('contacts.destroy')
->middleware(['auth:sanctum', 'verified']); ->middleware(['auth:sanctum', 'verified']);