@CodExe

Как получить данные с select в laravel?

Добрый день/вечер подскажите пожалуйста как сделать сохранения данных с select цикла.

Controller

namespace App\Http\Controllers\Front;

use Illuminate\Http\Request;
use App\Booking;
use App\Marka;
use App\Models;


class MarkaController extends Controller
{
    public function index()
    {
        $markasi = Marka::all();
		if ($this->frontThemeSettings->front_theme == 'theme-2') {
            return view('front-new.booking', ['markasi' => $markasi]);
        }
    }

    public function selectModels(Request $request){
        if($request->ajax()){
            $models = Models::where('id_markas',$request->id_markas)->get()->pluck("name","id");
            $data = view('selectmodels',['models' => $models])->render();
            return response()->json(['options'=>$data]);
        }
    }
}


booking.blade.php

<div class="col-md-6">
<div class="form-group mb-30 rounded userDetailForm">
		<select name="markaauto" id="markaauto" class="form-control form-control f-13 select2">
			<option disabled selected>@lang('front.registration.markaauto')</option>
			@foreach($markasi as $marka)
				<option value="{{ $marka->id }}">{{ $marka->name }}</option>
			@endforeach
		</select>
	</div>
</div>	
<div class="col-md-6">
	<div class="form-group mb-30 rounded userDetailForm">
		<select name="marka" id="marka" class="form-control form-control f-13 select2" >
			<option disabled selected>@lang('front.registration.marka')</option>
		</select>
	</div>
</div>


selectmodels.blode.php

<option>@lang('front.registration.marka')</option>
@if(!empty($models))
    @foreach($models as $key => $value)
        <option value="{{ $key }}">{{ $value }}</option>
    @endforeach
@endif


Сохранения сейчас вот так

public function saveBooking(StoreFrontBooking $request)
{
	if ($this->user) {
		$user = $this->user;

		$address = Address::firstOrNew(['user_id' => $user->id]);
		$address->marka = $request->marka;
		$address->markaauto = $request->markaauto;
		$address->vin = $request->vin;
		$address->yearauto = $request->yearauto;
		$address->save();
	}
}
  • Вопрос задан
  • 540 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы