Add member index

This commit is contained in:
philipp lang 2020-06-02 23:45:25 +02:00
parent 7dfad87896
commit 6054ee4add
10 changed files with 105 additions and 12 deletions

View File

@ -59,7 +59,7 @@ class InitializeMembers {
'active' => $data->status == 'Aktiv' 'active' => $data->status == 'Aktiv'
]; ];
$m = new \App\Member($attributes); $m = new \App\Member\Member($attributes);
$m->gender()->associate($gender); $m->gender()->associate($gender);
$m->country()->associate($country); $m->country()->associate($country);

View File

@ -1,8 +1,7 @@
<?php <?php
namespace App; namespace App\Member;
use App\Collections\OwnCollection;
use App\Events\MemberCreated; use App\Events\MemberCreated;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
@ -27,11 +26,15 @@ class Member extends Model
'nami_id' => 'integer', 'nami_id' => 'integer',
]; ];
public function newCollection(array $models = []) public function scopeSearch($q, $text) {
{ return $q->where('firstname', 'LIKE', '%'.$text.'%')
return new OwnCollection($models); ->orWhere('lastname', 'LIKE', '%'.$text.'%')
->orWhere('address', 'LIKE', '%'.$text.'%')
->orWhere('zip', 'LIKE', '%'.$text.'%')
->orWhere('city', 'LIKE', '%'.$text.'%');
} }
//----------------------------------- Getters ----------------------------------- //----------------------------------- Getters -----------------------------------
public function getFullnameAttribute() { public function getFullnameAttribute() {
return $this->firstname.' '.$this->lastname; return $this->firstname.' '.$this->lastname;
@ -65,21 +68,21 @@ class Member extends Model
public function way() public function way()
{ {
return $this->belongsTo(Way::class); return $this->belongsTo(App\Way::class);
} }
public function nationality() public function nationality()
{ {
return $this->belongsTo(Nationality::class); return $this->belongsTo(App\Nationality::class);
} }
public function memberships() public function memberships()
{ {
return $this->hasMany(Membership::class); return $this->hasMany(App\Membership::class);
} }
public function subscription() public function subscription()
{ {
return $this->belongsTo(Subscription::class); return $this->belongsTo(App\Subscription::class);
} }
} }

View File

@ -0,0 +1,15 @@
<?php
namespace App\Member;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class MemberController extends Controller
{
public function index(Request $request) {
return \Inertia::render('Member/Index', [
'data' => MemberResource::collection(Member::search($request->query('search', null))->get())
]);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Member;
use Illuminate\Http\Resources\Json\JsonResource;
class MemberResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -15,6 +15,8 @@ class AppServiceProvider extends ServiceProvider
public function register() public function register()
{ {
JsonResource::withoutWrapping(); JsonResource::withoutWrapping();
\Inertia::share('search', request()->query('search', ''));
} }
/** /**

23
package-lock.json generated
View File

@ -3124,8 +3124,7 @@
"decode-uri-component": { "decode-uri-component": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU="
"dev": true
}, },
"deep-equal": { "deep-equal": {
"version": "1.1.1", "version": "1.1.1",
@ -8312,6 +8311,16 @@
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==",
"dev": true "dev": true
}, },
"query-string": {
"version": "6.12.1",
"resolved": "https://registry.npmjs.org/query-string/-/query-string-6.12.1.tgz",
"integrity": "sha512-OHj+zzfRMyj3rmo/6G8a5Ifvw3AleL/EbcHMD27YA31Q+cO5lfmQxECkImuNVjcskLcvBRVHNAB3w6udMs1eAA==",
"requires": {
"decode-uri-component": "^0.2.0",
"split-on-first": "^1.0.0",
"strict-uri-encode": "^2.0.0"
}
},
"querystring": { "querystring": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
@ -9437,6 +9446,11 @@
} }
} }
}, },
"split-on-first": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz",
"integrity": "sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw=="
},
"split-string": { "split-string": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz", "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz",
@ -9540,6 +9554,11 @@
"integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==", "integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==",
"dev": true "dev": true
}, },
"strict-uri-encode": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz",
"integrity": "sha1-ucczDHBChi9rFC3CdLvMWGbONUY="
},
"string-width": { "string-width": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",

View File

@ -31,6 +31,7 @@
"js-modules": "file:resources/js/libs/js-modules", "js-modules": "file:resources/js/libs/js-modules",
"laravel-echo": "^1.7.0", "laravel-echo": "^1.7.0",
"postcss-import": "^12.0.1", "postcss-import": "^12.0.1",
"query-string": "^6.12.1",
"socket.io-client": "^2.3.0", "socket.io-client": "^2.3.0",
"tailwindcss": "^1.2.0", "tailwindcss": "^1.2.0",
"vue-inputmask": "^0.2.1", "vue-inputmask": "^0.2.1",

View File

@ -3,6 +3,7 @@ export default {
open: false, open: false,
links: [ links: [
{ icon: 'home', href: '/', title: 'Dashboard' }, { icon: 'home', href: '/', title: 'Dashboard' },
{ icon: 'user', href: '/member', title: 'Mitglieder' },
] ]
}, },
footer: { footer: {

View File

@ -0,0 +1,31 @@
<template>
<div>
<v-table :headers="[
{text: 'Nachname', value: 'lastname', align: 'left'},
{text: 'Vorname', value: 'firstname', align: 'left'},
{text: 'Adresse', value: 'address', align: 'left'},
]" :items="data" actions>
<template slot="Nachname" slot-scope="{item}">
{{item.lastname}}
</template>
<template slot="Vorname" slot-scope="{item}">
{{item.firstname}}
</template>
<template slot="Adresse" slot-scope="{item}">
{{item.address}} {{item.zip}}, {{item.city}}
</template>
<template slot="Aktion" slot-scope="{item}"></template>
</v-table>
</div>
</template>
<script>
import App from '../../layouts/App';
export default {
layout: App,
props: ['data']
}
</script>

View File

@ -1,5 +1,6 @@
<?php <?php
use App\Member\MemberController;
use App\Http\Controllers\HomeController; use App\Http\Controllers\HomeController;
use App\Initialize\InitializeController; use App\Initialize\InitializeController;
@ -10,5 +11,6 @@ Route::group(['namespace' => 'App\\Http\\Controllers'], function() {
Route::group(['middleware' => 'auth:web'], function () { Route::group(['middleware' => 'auth:web'], function () {
Route::get('/', HomeController::class)->name('home'); Route::get('/', HomeController::class)->name('home');
Route::resource('initialize', InitializeController::class); Route::resource('initialize', InitializeController::class);
Route::resource('member', MemberController::class);
}); });