もくじ
HTML
<select name="prefectures"> <option value="1" >北海道</option> <option value="2" >青森県</option> <option value="3" >岩手県</option> <option value="4" >宮城県</option> <option value="5" >秋田県</option> <option value="6" >山形県</option> <option value="7" >福島県</option> <option value="8" >茨城県</option> <option value="9" >栃木県</option> <option value="10" >群馬県</option> <option value="11" >埼玉県</option> <option value="12" >千葉県</option> <option value="13" >東京都</option> <option value="14" >神奈川県</option> <option value="15" >新潟県</option> <option value="16" >富山県</option> <option value="17" >石川県</option> <option value="18" >福井県</option> <option value="19" >山梨県</option> <option value="20" >長野県</option> <option value="21" >岐阜県</option> <option value="22" >静岡県</option> <option value="23" >愛知県</option> <option value="24" >三重県</option> <option value="25" >滋賀県</option> <option value="26" >京都府</option> <option value="27" >大阪府</option> <option value="28" >兵庫県</option> <option value="29" >奈良県</option> <option value="30" >和歌山県</option> <option value="31" >鳥取県</option> <option value="32" >島根県</option> <option value="33" >岡山県</option> <option value="34" >広島県</option> <option value="35" >山口県</option> <option value="36" >徳島県</option> <option value="37" >香川県</option> <option value="38" >愛媛県</option> <option value="39" >高知県</option> <option value="40" >福岡県</option> <option value="41" >佐賀県</option> <option value="42" >長崎県</option> <option value="43" >熊本県</option> <option value="44" >大分県</option> <option value="45" >宮崎県</option> <option value="46" >鹿児島県</option> <option value="47" >沖縄県</option> </select>
/app/Http/Controllers/PersonController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Person; class PersonController extends Controller { public function user_list(){ $people = new Person(); $users = $people->select(); return view('users.list', ['users' => $users]); } }
/app/Http/Models/Person.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; class Person extends Model { protected $table = 'people'; protected $guarded = array('id'); public function select(){ $users = DB::table('people') ->join('category' , 'people.category_id', '=', 'category.id' ) ->join('prefectures', 'people.prefectures_id', '=', 'prefectures.id' ) ->join('generation', 'people.generation_id', '=', 'generation.id' ) ->select('people.*', 'category.category_name', 'prefectures.prefectures_name', 'generation.generation_name') ->orderBy('people.id', 'DESC') ->paginate(3); return $users; } }