Witam serdecznie.
Zaczynam przygodę z Laravelem i natrafiłem na mały problem
Wykorzystuję w moim projekcie Laravel 5.8.
Mam działający kod wyświetlający listę użytkowników.
Mój kod wygląda następująco:
Users:
class User extends Authenticatable implements MustVerifyEmail { use Notifiable; use psCMS\Presenters\UserPresenter; public http://www.php.net/static $roles = []; protected $fillable = ['user_height', 'year_birth', 'company_id', 'enable', 'name', 'surname', 'email', 'email_verified_at', 'password', 'counter', 'url_address', 'isCompany', 'isMailing', 'content', 'nip1', 'business1', 'phone1', 'street1', 'number1', 'postal_code1', 'city1', 'country_id1', 'provincial_id1', 'nip2', 'business2', 'phone2', 'street2', 'number2', 'postal_code2', 'city2', 'country_id2', 'provincial_id2', 'nip3', 'business3', 'phone3', 'street3', 'number3', 'postal_code3', 'city3', 'country_id3', 'provincial_id3', 'cash', 'lng', 'lat', 'enable_map', 'remember_token', 'created_at', 'updated_at', 'last_login_at', 'last_login_ip']; protected $hidden = [ 'password', 'remember_token', ]; public function roles() { return $this->belongsToMany('App\Role'); } public function mainRole() { return $this->hasOne('App\Role'); } } Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); $table->bigInteger('company_id')->unsigned(); $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); $table->boolean('enable')->default(0); $table->string('name', 120)->nullable(); $table->string('surname', 120)->nullable(); $table->string('email', 120)->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->bigInteger('counter')->default(0); $table->string('url_address', 160); $table->boolean('isCompany')->default(0); $table->boolean('isMailing')->default(0); $table->text('content')->nullable(); $table->string('nip1', 12)->nullable(); $table->string('business1', 120)->nullable(); $table->string('phone1', 60)->nullable(); $table->string('street1', 150)->nullable(); $table->string('number1', 8)->nullable(); $table->string('postal_code1', 12)->nullable(); $table->string('city1', 100)->nullable(); $table->bigInteger('country_id1')->default(0); $table->bigInteger('provincial_id1')->default(0); $table->string('nip2', 12)->nullable(); $table->string('business2', 120)->nullable(); $table->string('phone2', 60)->nullable(); $table->string('street2', 150)->nullable(); $table->string('number2', 8)->nullable(); $table->string('postal_code2', 12)->nullable(); $table->string('city2', 100)->nullable(); $table->bigInteger('country_id2')->default(0); $table->bigInteger('provincial_id2')->default(0); $table->string('nip3', 12)->nullable(); $table->string('business3', 120)->nullable(); $table->string('phone3', 60)->nullable(); $table->string('street3', 150)->nullable(); $table->string('number3', 8)->nullable(); $table->string('postal_code3', 12)->nullable(); $table->string('city3', 100)->nullable(); $table->bigInteger('country_id3')->default(0); $table->bigInteger('provincial_id3')->default(0); $table->decimal('cash', 9, 2)->default(0); $table->decimal('lng', 10, 8)->default(0); $table->decimal('lat', 10, 8)->default(0); $table->boolean('enable_map')->default(0); $table->integer('year_birth')->default(http://www.php.net/date("Y")); $table->integer('user_height')->default(0); $table->rememberToken(); $table->timestamps(); $table->engine = "InnoDB"; });
class UsersServices extends Model { protected $quarded = []; protected $fillable = ['name', 'type', 'enable']; public $timestamps = false; } Schema::create('users_services', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name', 100); $table->integer('type'); $table->boolean('enable')->default(0); $table->engine = "InnoDB"; });
Schema::create('users_services_selected', function (Blueprint $table) { $table->bigInteger('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->bigInteger('service_id')->unsigned(); $table->foreign('service_id')->references('id')->on('users_services')->onDelete('cascade'); $table->engine = "InnoDB"; }); class UserServicesSelected extends Model { protected $quarded = []; protected $fillable = ['user_id', 'service_id']; protected $table = 'users_services_selected'; public $timestamps = false; }
public function getUserList(string $query, string $sortColumn, string $sortMethod) { if ($query != "" || $sortMethod !="") { http://www.php.net/echo "$sortColumn, $sortMethod"; return User::ofRoleType(['user', 'userPremium', 'userSponsor']) ->where(function ($q) use ($query, $sortColumn, $sortMethod) { $q->where('account_paid_for', '>=', http://www.php.net/date("Y-m-d")) ->where('enable', '=', 1) ->where('email_verified_at', '<>', null) ->orderBy($sortColumn, $sortMethod); })->orderBy($sortColumn, $sortMethod)->paginate(15); } else { return User::ofRoleType(['user', 'userPremium', 'userSponsor']) ->where('account_paid_for', '>=', http://www.php.net/date("Y-m-d")) ->where('enable', '=', 1) ->where('email_verified_at', '<>', null) ->orderBy(DB::raw('IF(premium_for > CURDATE(), 0, 1)')) ->orderBy('hits', 'DESC') ->paginate(15); } }
<http://december.com/html/4/element/form.html method="get" action="{{ route('result') }}"> Wiek od <http://december.com/html/4/element/input.html type="text" name="s_year_birth_from" value=""></http://december.com/html/4/element/div.html> Wiek do <http://december.com/html/4/element/input.html type="text" name="s_year_birth_to" value=""></http://december.com/html/4/element/div.html> Wzrost użytkownika: Pokaż wszystko: <http://december.com/html/4/element/input.html type="checkbox" value="0" name="s_height[]"> 150 cm: <http://december.com/html/4/element/input.html type="checkbox" value="1" name="s_height[]"> 151-160 cm: <http://december.com/html/4/element/input.html type="checkbox" value="2" name="s_height[]"> 161-170 cm: <http://december.com/html/4/element/input.html type="checkbox" value="3" name="s_height[]"> 171-180 cm: <http://december.com/html/4/element/input.html type="checkbox" value="4" name="s_height[]"> >180 cm: <http://december.com/html/4/element/input.html type="checkbox" value="5" name="s_height[]"> Usługi: Pokaż wszystko: <http://december.com/html/4/element/input.html type="checkbox" value="0" name="s_services1[]"> @foreach($services as $service) {{ $service->name }} <http://december.com/html/4/element/input.html type="checkbox" value="{{ $service->id }}" name="s_services1[]"> @endforeach <http://december.com/html/4/element/button.html type="submit">Szukaj</http://december.com/html/4/element/button.html> </http://december.com/html/4/element/form.html>
nip1, nip2, nip3.. Hmmm.. Może jeszcze nip4, i nip5.. Zwracam uwagę też, że nip to po angielsku co najwyżej może się kojarzyć z sutkiem..
Klasa typu service, w której jest kod migracji i parametry z modelu? O co tu chodzi?
Data urodzenia, w której ma być domyślnie rok utworzenia tabeli? Poza tym nie lepiej datę?
Wzrost domyślnie wynosi 0?
CamelCase i under score w jednej tabeli.
bigInteger dla kraju? Serio mamy 4 biliony Państw na ziemi?
engine jest domyślnie innodb, klucze obce warto wydzielić wizualnie pod deklarację tabeli, lepiej się czyta.
W funkcjach jakieś echo.
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)