fix minor stuff

shift-build-2464
Nadim Salloum 2021-05-10 21:22:05 +02:00
parent a1fc63dd8e
commit 68ca52f6c4
21 changed files with 401 additions and 44 deletions

View File

@ -14,7 +14,31 @@ class CarController extends Controller
*/
public function index()
{
//
return Inertia::render('Cars/Index', [
'filters' => Request::all('search', 'trashed'),
'cars' => Car::all()
->orderByName()
->filter(Request::only('search', 'trashed'))
->paginate()
->withQueryString()
->through(function ($car) {
return [
'id' => $car->id,
'stammnummer' => $car->stammnummer,
'vin' => $car->vin,
'bought_at' => $car->bought_at,
'buy_price' => $car->buy_price,
'seller' => $car->seller->only('name');
'buyer' => $car->buyer->only('name');
'car_model' => $car->carModel->only('name'),
'name' => $car->name,
'phone' => $car->phone,
'zipcode' => $car->city,
'city' => $car->city,
'deleted_at' => $car->deleted_at,
];
}),
]);
}
/**
@ -24,7 +48,7 @@ class CarController extends Controller
*/
public function create()
{
//
return Inertia::render('Cars/Create');
}
/**
@ -80,6 +104,14 @@ class CarController extends Controller
*/
public function destroy(Car $car)
{
//
$car->delete();
return Redirect::back()->with('success', 'Auto gelöscht.');
}
public function restore(Car $car)
{
$car->restore();
return Redirect::back()->with('success', 'Auto wiederhergestellt.');
}
}

View File

@ -14,7 +14,24 @@ class ContactController extends Controller
*/
public function index()
{
//
return Inertia::render('Contacts/Index', [
'filters' => Request::all('search', 'trashed'),
'contacts' => Contact::all()
->orderByName()
->filter(Request::only('search', 'trashed'))
->paginate()
->withQueryString()
->through(function ($contact) {
return [
'id' => $contact->id,
'name' => $contact->name,
'phone' => $contact->phone,
'zipcode' => $contact->city,
'city' => $contact->city,
'deleted_at' => $contact->deleted_at,
];
}),
]);
}
/**
@ -24,7 +41,7 @@ class ContactController extends Controller
*/
public function create()
{
//
return Inertia::render('Contacts/Create');
}
/**
@ -35,18 +52,21 @@ class ContactController extends Controller
*/
public function store(Request $request)
{
//
}
Contact::create(
Request::validate([
'firstname' => ['required', 'max:75'],
'lastname' => ['required', 'max:75'],
'email' => ['nullable', 'max:75', 'email'],
'phone' => ['max:75'],
'address' => ['nullable', 'max:150'],
'zipcode' => ['nullable', 'max:6'],
'city' => ['nullable', 'max:75'],
'country' => ['nullable', 'max:2'],
'company' => ['nullable', 'max:75'],
])
);
/**
* Display the specified resource.
*
* @param \App\Models\Contact $contact
* @return \Illuminate\Http\Response
*/
public function show(Contact $contact)
{
//
return Redirect::route('contacts')->with('success', 'Kontakt erstellt.');
}
/**
@ -57,7 +77,20 @@ class ContactController extends Controller
*/
public function edit(Contact $contact)
{
//
return Inertia::render('Contacts/Edit', [
'contact' => [
'id' => $contact->id,
'firstname' => $contact->first_name,
'lastname' => $contact->last_name,
'email' => $contact->email,
'phone' => $contact->phone,
'address' => $contact->address,
'zipcode' => $contact->postal_code,
'city' => $contact->city,
'country' => $contact->country,
'deleted_at' => $contact->deleted_at,
]
]);
}
/**
@ -69,7 +102,21 @@ class ContactController extends Controller
*/
public function update(Request $request, Contact $contact)
{
//
$contact->update(
Request::validate([
'firstname' => ['required', 'max:75'],
'lastname' => ['required', 'max:75'],
'email' => ['nullable', 'max:75', 'email'],
'phone' => ['max:75'],
'address' => ['nullable', 'max:150'],
'zipcode' => ['nullable', 'max:6'],
'city' => ['nullable', 'max:75'],
'country' => ['nullable', 'max:2'],
'company' => ['nullable', 'max:75'],
])
);
return Redirect::route('contacts')->with('success', 'Kontakt geändert.');
}
/**
@ -80,6 +127,14 @@ class ContactController extends Controller
*/
public function destroy(Contact $contact)
{
//
$contact->delete();
return Redirect::back()->with('success', 'Kontakt gelöscht.');
}
public function restore(Contact $contact)
{
$contact->restore();
return Redirect::back()->with('success', 'Kontakt wiederhergestellt.');
}
}

View File

@ -37,7 +37,22 @@ class HandleInertiaRequests extends Middleware
public function share(Request $request)
{
return array_merge(parent::share($request), [
//
'auth' => function () use ($request) {
return [
'user' => $request->user() ? [
'id' => $request->user()->id,
'firstname' => $request->user()->firstname,
'lastname' => $request->user()->lastname,
'email' => $request->user()->email,
] : null,
];
},
'flash' => function () use ($request) {
return [
'success' => $request->session()->get('success'),
'error' => $request->session()->get('error'),
];
},
]);
}
}

View File

@ -9,7 +9,7 @@ class Brand extends Model
{
use HasFactory;
protected $fillable = ['brand'];
protected $fillable = ['name'];
public function cars()
{
@ -20,4 +20,17 @@ class Brand extends Model
{
return $this->hasMany(CarModel::class);
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where('name', 'like', '%'.$search.'%');
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
$query->onlyTrashed();
}
});
}
}

View File

@ -4,14 +4,15 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Car extends Model
{
use HasFactory;
use HasFactory, softDeletes;
protected $fillable = [
'variation',
'variation',
'stammnummer',
'vin',
'colour',
'notes',
@ -23,6 +24,11 @@ class Car extends Model
'car_model_id'
];
public function getNameAttribute()
{
return $this->brand->name . ' ' . $this->carModel->car_model . $this->variation ? '(' . $this->variation . ')' : '';
}
public function brand()
{
return $this->hasOneThrough(Brand::class, CarModel::class);

View File

@ -4,16 +4,17 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Contact extends Model
{
use HasFactory;
use HasFactory, softDeletes;
protected $fillable = [
'firstname',
'lastname',
'phone',
'street',
'address',
'zip',
'city',
'country',
@ -22,6 +23,11 @@ class Contact extends Model
'notes',
];
public function scopeOrderByName($query)
{
$query->orderBy('lastname')->orderBy('firstname');
}
public function contracts()
{
return $this->hasMany(Contracts::class);
@ -36,4 +42,21 @@ class Contact extends Model
{
return $this->hasMany(Car::class, 'seller_id');
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where(function ($query) use ($search) {
$query->where('firstname', 'like', '%' . $search . '%')
->orWhere('lastname', 'like', '%' . $search . '%')
->orWhere('email', 'like', '%' . $search . '%');
});
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
$query->onlyTrashed();
}
});
}
}

View File

@ -4,10 +4,11 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Contract extends Model
{
use HasFactory;
use HasFactory, softDeletes;
protected $fillable = [
'sold_at',

View File

@ -22,7 +22,7 @@ class BrandFactory extends Factory
public function definition()
{
return [
'brand' => $this->faker->word(),
'name' => $this->faker->word(),
];
}
}

View File

@ -23,7 +23,7 @@ class CarModelFactory extends Factory
public function definition()
{
return [
'car_model' => $this->faker->word(),
'name' => $this->faker->word(),
'brand_id' => $this->faker->numberBetween(1, Brand::count()),
];
}

View File

@ -29,8 +29,8 @@ class ContactFactory extends Factory
'firstname' => $this->faker->firstName(),
'lastname' => $this->faker->lastName(),
'phone' => $this->faker->PhoneNumber(),
'street' => $this->faker->streetName(),
'zip' => $this->faker->postcode(),
'address' => $this->faker->streetName() . ' ' . $this->faker->buildingNumber(),
'zip' => $this->faker->randomNumber(4, true),
'city' => $this->faker->city(),
'country' => $this->faker->countryCode(),
'company' => $this->faker->company(),

View File

@ -15,7 +15,7 @@ class CreateBrandsTable extends Migration
{
Schema::create('brands', function (Blueprint $table) {
$table->id();
$table->string('brand')->unique();
$table->string('name')->unique();
$table->timestamps();
});
}

View File

@ -15,17 +15,18 @@ class CreateContactsTable extends Migration
{
Schema::create('contacts', function (Blueprint $table) {
$table->id();
$table->string('firstname')->nullable();
$table->string('lastname')->nullable();
$table->string('phone');
$table->string('street')->nullable();
$table->string('zip')->nullable();
$table->string('city')->nullable();
$table->string('country')->nullable();
$table->string('company')->nullable();
$table->string('email')->nullable();
$table->string('firstname', 75)->nullable();
$table->string('lastname', 75)->nullable();
$table->string('phone', 75);
$table->string('address', 150)->nullable();
$table->string('zip', 6)->nullable();
$table->string('city', 75)->nullable();
$table->string('country', 2)->nullable();
$table->string('company', 75)->nullable();
$table->string('email', 75)->nullable();
$table->text('notes')->nullable();
$table->timestamps();
$table->softDeletes();
});
}

View File

@ -15,7 +15,7 @@ class CreateCarModelsTable extends Migration
{
Schema::create('car_models', function (Blueprint $table) {
$table->id();
$table->string('car_model');
$table->string('name');
$table->foreignId('brand_id')
->onUpdate('cascade')
->onDelete('cascade')

View File

@ -30,7 +30,7 @@ class CreateCarsTable extends Migration
->onDelete('cascade')
->constrained('car_models');
$table->timestamps();
$table->softDeletes();
$table->foreign('seller_contact_id')->references('id')->on('contacts');
});
}

View File

@ -29,6 +29,7 @@ class CreateContractsTable extends Migration
$table->enum('insurance_type', InsuranceType::getValues())
->default(InsuranceType::OptionOne);
$table->timestamps();
$table->softDeletes();
});
}

View File

@ -4,6 +4,7 @@ namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Team;
use App\Models\Car;
use App\Models\CarModel;
use App\Models\Brand;
@ -23,6 +24,7 @@ class DatabaseSeeder extends Seeder
public function run()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
User::truncate();
CarPayment::truncate();
Contract::truncate();
Document::truncate();
@ -31,9 +33,21 @@ class DatabaseSeeder extends Seeder
CarModel::truncate();
Brand::truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
$user = User::factory()->create([
'name' => 'Nadim Salloum',
'email' => 'hello@salloum.ch',
'password' => bcrypt('abc123'),
]);
$team = Team::factory()->create([
'name' => 'Your SwissCar GmbH',
'user_id' => $user->id,
'personal_team' => false,
]);
foreach ($this->getBrands() as $brand) {
Brand::create(['brand' => $brand]);
Brand::create(['name' => $brand]);
}
$carModels = CarModel::factory()

60
public/js/app.js vendored
View File

@ -47509,6 +47509,60 @@ _VerifyEmail_vue_vue_type_script_lang_js__WEBPACK_IMPORTED_MODULE_1__.default.__
/***/ }),
/***/ "./resources/js/Pages/Contacts/Create.vue":
/*!************************************************!*\
!*** ./resources/js/Pages/Contacts/Create.vue ***!
\************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
const script = {}
script.__file = "resources/js/Pages/Contacts/Create.vue"
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (script);
/***/ }),
/***/ "./resources/js/Pages/Contacts/Edit.vue":
/*!**********************************************!*\
!*** ./resources/js/Pages/Contacts/Edit.vue ***!
\**********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
const script = {}
script.__file = "resources/js/Pages/Contacts/Edit.vue"
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (script);
/***/ }),
/***/ "./resources/js/Pages/Contacts/Index.vue":
/*!***********************************************!*\
!*** ./resources/js/Pages/Contacts/Index.vue ***!
\***********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
const script = {}
script.__file = "resources/js/Pages/Contacts/Index.vue"
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (script);
/***/ }),
/***/ "./resources/js/Pages/Dashboard.vue":
/*!******************************************!*\
!*** ./resources/js/Pages/Dashboard.vue ***!
@ -50070,6 +50124,12 @@ var map = {
"./Auth/TwoFactorChallenge.vue": "./resources/js/Pages/Auth/TwoFactorChallenge.vue",
"./Auth/VerifyEmail": "./resources/js/Pages/Auth/VerifyEmail.vue",
"./Auth/VerifyEmail.vue": "./resources/js/Pages/Auth/VerifyEmail.vue",
"./Contacts/Create": "./resources/js/Pages/Contacts/Create.vue",
"./Contacts/Create.vue": "./resources/js/Pages/Contacts/Create.vue",
"./Contacts/Edit": "./resources/js/Pages/Contacts/Edit.vue",
"./Contacts/Edit.vue": "./resources/js/Pages/Contacts/Edit.vue",
"./Contacts/Index": "./resources/js/Pages/Contacts/Index.vue",
"./Contacts/Index.vue": "./resources/js/Pages/Contacts/Index.vue",
"./Dashboard": "./resources/js/Pages/Dashboard.vue",
"./Dashboard.vue": "./resources/js/Pages/Dashboard.vue",
"./PrivacyPolicy": "./resources/js/Pages/PrivacyPolicy.vue",

View File

View File

View File

@ -0,0 +1,108 @@
<template>
<div>
<h1 class="mb-8 font-bold text-3xl">Kontakte</h1>
<div class="mb-6 flex justify-between items-center">
<search-filter v-model="form.search" class="w-full max-w-md mr-4" @reset="reset">
<label class="block text-gray-700">Trashed:</label>
<select v-model="form.trashed" class="mt-1 w-full form-select">
<option :value="null" />
<option value="with">With Trashed</option>
<option value="only">Only Trashed</option>
</select>
</search-filter>
<inertia-link class="btn-indigo" :href="route('contacts.create')">
<span>Create</span>
<span class="hidden md:inline">Contact</span>
</inertia-link>
</div>
<div class="bg-white rounded-md shadow overflow-x-auto">
<table class="w-full whitespace-nowrap">
<tr class="text-left font-bold">
<th class="px-6 pt-6 pb-4">Name</th>
<th class="px-6 pt-6 pb-4">Organization</th>
<th class="px-6 pt-6 pb-4">City</th>
<th class="px-6 pt-6 pb-4" colspan="2">Phone</th>
</tr>
<tr v-for="contact in contacts.data" :key="contact.id" class="hover:bg-gray-100 focus-within:bg-gray-100">
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center focus:text-indigo-500" :href="route('contacts.edit', contact.id)">
{{ contact.name }}
<icon v-if="contact.deleted_at" name="trash" class="flex-shrink-0 w-3 h-3 fill-gray-400 ml-2" />
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('contacts.edit', contact.id)" tabindex="-1">
<div v-if="contact.organization">
{{ contact.organization.name }}
</div>
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('contacts.edit', contact.id)" tabindex="-1">
{{ contact.city }}
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('contacts.edit', contact.id)" tabindex="-1">
{{ contact.phone }}
</inertia-link>
</td>
<td class="border-t w-px">
<inertia-link class="px-4 flex items-center" :href="route('contacts.edit', contact.id)" tabindex="-1">
<icon name="cheveron-right" class="block w-6 h-6 fill-gray-400" />
</inertia-link>
</td>
</tr>
<tr v-if="contacts.data.length === 0">
<td class="border-t px-6 py-4" colspan="4">No contacts found.</td>
</tr>
</table>
</div>
<pagination class="mt-6" :links="contacts.links" />
</div>
</template>
<script>
import Icon from '@/Shared/Icon'
import pickBy from 'lodash/pickBy'
import Layout from '@/Shared/Layout'
import throttle from 'lodash/throttle'
import mapValues from 'lodash/mapValues'
import Pagination from '@/Shared/Pagination'
import SearchFilter from '@/Shared/SearchFilter'
export default {
metaInfo: { title: 'Contacts' },
components: {
Icon,
Pagination,
SearchFilter,
},
layout: Layout,
props: {
filters: Object,
contacts: Object,
},
data() {
return {
form: {
search: this.filters.search,
trashed: this.filters.trashed,
},
}
},
watch: {
form: {
deep: true,
handler: throttle(function() {
this.$inertia.get(this.route('contacts'), pickBy(this.form), { preserveState: true })
}, 150),
},
},
methods: {
reset() {
this.form = mapValues(this.form, () => null)
},
},
}
</script>

View File

@ -27,3 +27,31 @@ Route::get('/', function () {
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return Inertia::render('Dashboard');
})->name('dashboard');
Route::get('contacts', [ContactsController::class, 'index'])
->name('contacts')
->middleware(['auth:sanctum', 'verified']);
Route::get('contacts/create', [ContactsController::class, 'create'])
->name('contacts.create')
->middleware(['auth:sanctum', 'verified']);
Route::post('contacts', [ContactsController::class, 'store'])
->name('contacts.store')
->middleware(['auth:sanctum', 'verified']);
Route::get('contacts/{contact}/edit', [ContactsController::class, 'edit'])
->name('contacts.edit')
->middleware(['auth:sanctum', 'verified']);
Route::put('contacts/{contact}', [ContactsController::class, 'update'])
->name('contacts.update')
->middleware(['auth:sanctum', 'verified']);
Route::delete('contacts/{contact}', [ContactsController::class, 'destroy'])
->name('contacts.destroy')
->middleware(['auth:sanctum', 'verified']);
Route::put('contacts/{contact}/restore', [ContactsController::class, 'restore'])
->name('contacts.restore')
->middleware(['auth:sanctum', 'verified']);