返回重定向Laravel

时间:2020-07-04 01:05:55

标签: laravel

我想返回链接为localhost:8000/order/show/O1/T1的页面。 O1$order->id_order,而T1$trip->id_trip

这是我的代码。

Route::get('/order/show/{id_order}/{id_trip}', 'OrderController@show');
Route::get('/order/update_driver/{id_order}/{id_trip}', 'OrderController@update_driver');

订单控制器

public function show($id_order, $id_trip){

    $trip = Trip::find($id_trip);
    $order = Order::where(['id_order' => $id_order, 'id_trip' => $id_trip])->first();   
    $detail_order = Detail_Order::where(['id_order' => $id_order, 'id_trip' => $id_trip])->first();   
    $detail = Order::join('detail_order', 'order.id_order', '=', 'detail_order.id_order')
                ->where('order.id_order', $id_order)
                ->select('order.id_trip as order_trip',
                         'order.id_order as order_id',
                         'order.id_users as order_users',
                         'order.date_order as order_date',
                         'detail_order.id_seat as detail_seat',
                         'detail_order.users as detail_users')
                ->get();
    $driver = Driver::all();            
    
    return view('travel.order.show', ['trip' => $trip, 'order' => $order, 'detail' => $detail, 'detail_order' => $detail_order, 'driver' => $driver]);
}

public function update_driver($id_order, $id_trip){

    $driver = Input::get('id_users_driver');
    Detail_Order::where('id_order', $id_order)
      ->update(['id_users_driver' => $driver]);  

    session()->flash('flash_success', 'Data has been updated');
    return redirect('/order/show/{id_order}/{id_trip}');        
}

查看

<form method="get" action="/order/update_driver/{{ $order->id_order}}/{{ $order->id_trip}}">
    <label>Driver</label>
    <select class="form-control" name="id_users_driver" id="id_users_driver">
          <option value=""> Driver </option>
                @foreach($driver as $d)
                   <option  value="{{$d->id_users}}"{{$detail_order->id_users_driver == $d->id_users ? 'selected' : ''}}>{{$d->name}}</option>                                         
                @endforeach
    </select>

    @if($errors->has('id_users_driver'))
        <div class="text-danger">
           {{ $errors->first('id_users_driver')}}
        </div>
    @endif

   <input type="submit" class="btn btn-primary" value="Save">                                    
 </form>

返回错误Trying to get property 'id_order' of non-object。 您知道如何使它返回到localhost:8000/order/show/O1/T1吗?谢谢

0 个答案:

没有答案