Php 如何在LAVEL 4中显示多个条目

Php 如何在LAVEL 4中显示多个条目,php,laravel,laravel-4,Php,Laravel,Laravel 4,如何显示新插入的条目?每当我试图同时提交两个或多个条目,并将其显示在我的刀片上时,它只会显示我插入的最后一个条目。这里有什么问题吗 Controller.php public function onewayflightshow() { $children=Session::get('children'); $adult=Session::get('adult'); $infant=Session::get('infant');

如何显示新插入的条目?每当我试图同时提交两个或多个条目,并将其显示在我的刀片上时,它只会显示我插入的最后一个条目。这里有什么问题吗

Controller.php

     public function onewayflightshow()
   {  
      $children=Session::get('children');
      $adult=Session::get('adult');
      $infant=Session::get('infant');
      $to=Session::get('destinationto');
      $from=Session::get('destinationfrom');
      $dept=Session::get('departure');
      $show = DB::table('oneways')->get();
        foreach ($show as $user)
        {  
            $adultFee = ($user->fare)*$adult;
            /*------------------------Child Fee------------------------*/
            $partialFee1 = ($user->fare)*.05;
            $partialFee2 = ($user->fare)-$partialFee1;
            $childFee = $partialFee2*$children;
            /*------------------------Infant Fee------------------------*/
            $partialFee3 = ($user->fare)*.10;
            $partialFee4 = ($user->fare)-$partialFee3;
            $infantFee = $partialFee2*$infant;
        }  
            $payment = ($adultFee+$childFee+$infantFee);

           $rules = array(
          'title'         => 'required',             
          'lastname'      => 'required',  
          'email'         => 'required',
          'cemail'        => 'required|same:email',    
          'firstname'     => 'required',
          'middlename'    => 'required',
          'birthday'      => 'required',
          'city'          => 'required',
          'streetadd'     => 'required',
          'zipcode'       => 'required|max:4',
          'country'       => 'required',
          'home'          => 'required|max:7',
          'mobile'        => 'required|max:12'
        );

      $validator = Validator::make(Input::all(), $rules);
      if ($validator->fails()) {

        $messages = $validator->messages();
        $guestcount= $children+$adult+$infant;
        return View::make('content.onewayflightfillup')->withErrors($validator)->with(['gcount'=>$guestcount]);
      }

      else{
          $c = count(Input::get('title'));

          $titles = Input::get('title');
          $lastnames = Input::get('lastname');
          $firstnames = Input::get('firstname');
          $middlenames = Input::get('middlename');
          $birthdays = Input::get('birthday');
          $citys = Input::get('city');
          $streetadds = Input::get('streetadd');
          $zipcodes = Input::get('zipcode');
          $countrys = Input::get('country');
          $homes = Input::get('home');
          $works = Input::get('work');
          $faxs = Input::get('fax');
          $mobiles = Input::get('mobile');
          $emails = Input::get('email');

          for( $i=0; $i < $c; ++$i ) {
            $reserve = new Reserves;
            $reserve->title = $titles[$i];
            $reserve->lastname = $lastnames[$i];
            $reserve->firstname= $firstnames[$i];
            $reserve->middlename = $middlenames[$i];
            $reserve->birthday = $birthdays[$i];
            $reserve->city = $citys[$i];
            $reserve->streetadd = $streetadds[$i];
            $reserve->zipcode = $zipcodes[$i];
            $reserve->country = $countrys[$i]; 
            $reserve->home = $homes[$i];
            $reserve->work = $works[$i];
            $reserve->fax = $faxs[$i];
            $reserve->mobile = $mobiles[$i];
            $reserve->email = $emails[$i];
            $reserve->children = $children;
            $reserve->adult = $adult;
            $reserve->infant = $infant;
            $reserve->destinationfrom = $from;
            $reserve->destinationto = $to;
            $reserve->departure = $dept;
            $reserve->payment = $payment;

            $reserve->save();  

        }
           $reserves = $reserve->id;
           $res = DB::table('reserves')->where('id', '=' ,$reserves)->get();  
           return View::make('content.onewayflightshow2')->with(['showing'=>$res]);
      }}
@foreach($showing as $row)
        <tr>
            <td>Guest:</td><b> 
            <td>{{$row -> firstname}}</td>
            <td>{{$row -> middlename}}</td>
            <td>{{$row -> lastname}}</td></b>
        </tr><br>
        <tr>
            <td>Birthday:</td>
            <td>{{$row -> birthday}}</td>
        </tr><br>
        <tr>
            <td>Address:</td>
            <td>{{$row -> streetadd}}</td>,
            <td>{{$row -> city}}</td></tr>,
            <td>{{$row -> country}}</td> :
            <td>{{$row -> zipcode}}</td>
        <tr><br>
        <tr>
            <td>Contact Details:</td><br>
            <ul>
              <li>Home: {{$row -> home}}</li>
              <li>Work: {{$row -> work}}</li>
              <li>Fax: {{$row -> fax}}</li>
              <li>Mobile: {{$row -> mobile}}</li>
              <li>Email: {{$row -> email}}</li>
            </ul>  
        <tr><br>
        <tr>
            <td>Boarding with a # of</td><br>
            <ul>
              <li><b>{{$row -> children}}</b> Children</li>
              <li><b>{{$row -> adult}}</b> Adult/s</li>
              <li><b>{{$row -> infant}}</b> Infant/s</li>
            </ul> 
        </tr><br>
        <tr>
            <td>Enroute:</td>
            <td>from <b>{{$row -> destinationfrom}}</b> to <b>{{$row -> destinationto}}</b></td><br>
            <td>Departure Date:</td>
            <td><b>{{$row -> departure}}</b></td>
        <tr><br>
        <tr>
           <td>Total Expense: </td>
           <td>&#x20b1;<b>{{$row -> payment}}.00</b></td></tr>
@endforeach
公共功能onewayflightshow()
{  
$children=Session::get('children');
$maintal=Session::get('maintal');
$baby=Session::get('baby');
$to=Session::get('destinationo');
$from=Session::get('destinationfrom');
$dept=Session::get(‘离开’);
$show=DB::table('oneways')->get();
foreach($show as$user)
{  
$adultFee=($user->fare)*$adultFee;
/*------------------------儿童费------------------------*/
$partialFee1=($user->fare)*.05;
$partialFee2=($user->fare)-$partialFee1;
$childFee=$partialFee2*$children;
/*------------------------婴儿费------------------------*/
$partialFee3=($user->fare)*.10;
$partialFee4=($user->fare)-$partialFee3;
$infantFee=$partialFee2*$baby;
}  
$payment=($adultFee+$childFee+$infantFee);
$rules=数组(
“标题”=>“必需”,
“lastname”=>“必需”,
'电子邮件'=>'必需',
“cemail”=>“必填项|相同:电子邮件”,
“firstname”=>“必需”,
“middlename”=>“必需”,
“生日”=>“必需”,
“城市”=>“必需”,
'streetadd'=>'required',
'zipcode'=>'必需|最大值:4',
'国家'=>'必需',
“主页”=>“必需”|最大值:7',
需要“移动”=>“最多12”
);
$validator=validator::make(输入::all(),$rules);
如果($validator->fails()){
$messages=$validator->messages();
$guestcount=$children+$成人+$Baby;
返回视图::make('content.onewayflightfillup')->withErrors($validator)->with(['gcount'=>$guestcount]);
}
否则{
$c=计数(输入::get('title');
$titles=Input::get('title');
$lastnames=Input::get('lastname');
$firstname=Input::get('firstname');
$middlename=Input::get('middlename');
$birthdays=Input::get('birthday');
$citys=Input::get('city');
$streetadds=Input::get('streetadd');
$zipcodes=Input::get('zipcode');
$countrys=Input::get('country');
$homes=Input::get('home');
$works=Input::get('work');
$faxs=Input::get('fax');
$mobiles=Input::get('mobile');
$emails=Input::get('email');
对于($i=0;$i<$c;++$i){
$准备金=新准备金;
$reserve->title=$titles[$i];
$reserve->lastname=$lastnames[$i];
$reserve->firstname=$firstname[$i];
$reserve->middlename=$middlenames[$i];
$reserve->birthday=$birthdays[$i];
$reserve->city=$citys[$i];
$reserve->streetadd=$streetadds[$i];
$reserve->zipcode=$zipcodes[$i];
$reserve->country=$countrys[$i];
$reserve->home=$homes[$i];
$reserve->work=$works[$i];
$reserve->fax=$faxs[$i];
$reserve->mobile=$mobiles[$i];
$reserve->email=$emails[$i];
$reserve->children=$children;
$reserve->maintal=$maintal;
$reserve->baby=$baby;
$reserve->destinationfrom=$from;
$reserve->destinationo=$to;
$reserve->dept=$dept;
$reserve->payment=$payment;
$reserve->save();
}
$reserves=$reserve->id;
$res=DB::table('reserves')->其中('id','=',$reserves)->get();
返回视图::make('content.onewayflightshow2')->带有(['showing'=>$res]);
}}
blade.php

     public function onewayflightshow()
   {  
      $children=Session::get('children');
      $adult=Session::get('adult');
      $infant=Session::get('infant');
      $to=Session::get('destinationto');
      $from=Session::get('destinationfrom');
      $dept=Session::get('departure');
      $show = DB::table('oneways')->get();
        foreach ($show as $user)
        {  
            $adultFee = ($user->fare)*$adult;
            /*------------------------Child Fee------------------------*/
            $partialFee1 = ($user->fare)*.05;
            $partialFee2 = ($user->fare)-$partialFee1;
            $childFee = $partialFee2*$children;
            /*------------------------Infant Fee------------------------*/
            $partialFee3 = ($user->fare)*.10;
            $partialFee4 = ($user->fare)-$partialFee3;
            $infantFee = $partialFee2*$infant;
        }  
            $payment = ($adultFee+$childFee+$infantFee);

           $rules = array(
          'title'         => 'required',             
          'lastname'      => 'required',  
          'email'         => 'required',
          'cemail'        => 'required|same:email',    
          'firstname'     => 'required',
          'middlename'    => 'required',
          'birthday'      => 'required',
          'city'          => 'required',
          'streetadd'     => 'required',
          'zipcode'       => 'required|max:4',
          'country'       => 'required',
          'home'          => 'required|max:7',
          'mobile'        => 'required|max:12'
        );

      $validator = Validator::make(Input::all(), $rules);
      if ($validator->fails()) {

        $messages = $validator->messages();
        $guestcount= $children+$adult+$infant;
        return View::make('content.onewayflightfillup')->withErrors($validator)->with(['gcount'=>$guestcount]);
      }

      else{
          $c = count(Input::get('title'));

          $titles = Input::get('title');
          $lastnames = Input::get('lastname');
          $firstnames = Input::get('firstname');
          $middlenames = Input::get('middlename');
          $birthdays = Input::get('birthday');
          $citys = Input::get('city');
          $streetadds = Input::get('streetadd');
          $zipcodes = Input::get('zipcode');
          $countrys = Input::get('country');
          $homes = Input::get('home');
          $works = Input::get('work');
          $faxs = Input::get('fax');
          $mobiles = Input::get('mobile');
          $emails = Input::get('email');

          for( $i=0; $i < $c; ++$i ) {
            $reserve = new Reserves;
            $reserve->title = $titles[$i];
            $reserve->lastname = $lastnames[$i];
            $reserve->firstname= $firstnames[$i];
            $reserve->middlename = $middlenames[$i];
            $reserve->birthday = $birthdays[$i];
            $reserve->city = $citys[$i];
            $reserve->streetadd = $streetadds[$i];
            $reserve->zipcode = $zipcodes[$i];
            $reserve->country = $countrys[$i]; 
            $reserve->home = $homes[$i];
            $reserve->work = $works[$i];
            $reserve->fax = $faxs[$i];
            $reserve->mobile = $mobiles[$i];
            $reserve->email = $emails[$i];
            $reserve->children = $children;
            $reserve->adult = $adult;
            $reserve->infant = $infant;
            $reserve->destinationfrom = $from;
            $reserve->destinationto = $to;
            $reserve->departure = $dept;
            $reserve->payment = $payment;

            $reserve->save();  

        }
           $reserves = $reserve->id;
           $res = DB::table('reserves')->where('id', '=' ,$reserves)->get();  
           return View::make('content.onewayflightshow2')->with(['showing'=>$res]);
      }}
@foreach($showing as $row)
        <tr>
            <td>Guest:</td><b> 
            <td>{{$row -> firstname}}</td>
            <td>{{$row -> middlename}}</td>
            <td>{{$row -> lastname}}</td></b>
        </tr><br>
        <tr>
            <td>Birthday:</td>
            <td>{{$row -> birthday}}</td>
        </tr><br>
        <tr>
            <td>Address:</td>
            <td>{{$row -> streetadd}}</td>,
            <td>{{$row -> city}}</td></tr>,
            <td>{{$row -> country}}</td> :
            <td>{{$row -> zipcode}}</td>
        <tr><br>
        <tr>
            <td>Contact Details:</td><br>
            <ul>
              <li>Home: {{$row -> home}}</li>
              <li>Work: {{$row -> work}}</li>
              <li>Fax: {{$row -> fax}}</li>
              <li>Mobile: {{$row -> mobile}}</li>
              <li>Email: {{$row -> email}}</li>
            </ul>  
        <tr><br>
        <tr>
            <td>Boarding with a # of</td><br>
            <ul>
              <li><b>{{$row -> children}}</b> Children</li>
              <li><b>{{$row -> adult}}</b> Adult/s</li>
              <li><b>{{$row -> infant}}</b> Infant/s</li>
            </ul> 
        </tr><br>
        <tr>
            <td>Enroute:</td>
            <td>from <b>{{$row -> destinationfrom}}</b> to <b>{{$row -> destinationto}}</b></td><br>
            <td>Departure Date:</td>
            <td><b>{{$row -> departure}}</b></td>
        <tr><br>
        <tr>
           <td>Total Expense: </td>
           <td>&#x20b1;<b>{{$row -> payment}}.00</b></td></tr>
@endforeach
@foreach($显示为$row)
嘉宾:
{{$row->firstname}
{{$row->middlename}
{{$row->lastname}

生日: {{$row->生日}
地址: {{$row->streetadd}, {{$row->city}, {{$row->country}}: {{$row->zipcode}
联系方式:
  • 主页:{{$row->Home}
  • 工作:{{$row->Work}
  • 传真:{{$row->Fax}
  • 移动:{{$row->Mobile}
  • 电子邮件:{{$row->Email}


  • {{$row->children}}children
  • {{$row->成人}}成人/s
  • {{$row->baby}}baby/s

途中: 从{{$row->destinationfrom}}到{{$row->destinationon}}
出发日期: {{$row->出发}
总费用: ₱;{{$row->payment}.00 @endforeach
您应该更改:

  for( $i=0; $i < $c; ++$i ) {
    $reserve = new Reserves;
    // ...
    $reserve->payment = $payment;

    $reserve->save();  

}
进入:

$res = DB::table('reserves')->whereIn('id', $resIds)->get();