Русское сообщество разработки на PHP-фреймворке Laravel.
Ты не вошёл. Вход тут.
Страницы 1
Здравствуйте. Помогите с ситуацией
прошу не судить строго
Не могу подставить значение для Select из базы при редактировании записи
подставляется значение из foreach
файл шаблоне blade файл редактирование записи
@extends('layouts.teacher')
@section('content')
<div class="container" style="text-align: center;" >
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Курсты өңдеу
</h2>
<div class="row justify-content-center">
<div class="col-md-8" style="background-color: white; padding-top: 10px; ">
@if(Session::has('success'))
<div class="alert alert-success" role="alert">
{{Session::get('success')}}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('Course.update', $data->id)}}"method="post">
@csrf
@method('patch')
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Курс түрі</label>
<div class="col-md-6">
<input type="text" class="form-control" name="course_type" value="{{$data->course_type}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="user_id" value="{{$data->user_id}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Деңгей</label>
<div class="col-md-6">
<select class="form-control m-bot15" name="levelc" style="margin-bottom: 10px; appearance:auto;" defaultvalue="{{$data->levelc}}">
@if($roles->count() > 0)
@foreach($roles as $role)
<option value="{{$role->name}}">{{$role->name}}</option>
@endForeach
@else
No Record Found
@endif
</select>
<!-- <input type="text" class="form-control" name="levelc" value="{{$data->levelc}}"> -->
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Мемлекет</label>
<div class="col-md-6">
<input type="text" class="form-control" name="country" value="{{$data->country}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Оқыған тілі</label>
<div class="col-md-6">
<select class="form-control m-bot15" name="language" style="margin-bottom: 10px; appearance:auto;">
@if($langs->count() > 0)
@foreach($langs as $lng)
<option value="{{$lng->name}}">{{$lng->name}}</option>
@endForeach
@else
No Record Found
@endif
</select>
<!-- <input type="text" class="form-control" name="language" value="{{$data->language}}"> -->
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Қала</label>
<div class="col-md-6">
<input type="text" class="form-control" name="city" value="{{$data->city}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Курс тақырыбы</label>
<div class="col-md-6">
<input type="text" class="form-control" name="theme" value="{{$data->theme}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Сағат</label>
<div class="col-md-6">
<input type="text" class="form-control" name="clock" value="{{$data->clock}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Басталу уақыты</label>
<div class="col-md-6">
<input type="date" class="form-control" name="start_time" value="{{$data->start_time}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Аяқталу уақыты</label>
<div class="col-md-6">
<input type="date" class="form-control" name="end_time" value="{{$data->end_time}}">
</div>
</div>
<div class="row mb-3">
<label class="col-md-4 col-form-label text-md-end">Суреті</label>
<div class="col-md-6">
<input type="text" class="form-control" name="photo" value="{{$data->photo}}">
</div>
</div>
<button type="submit" class="btn btn-primary" style="margin-bottom:10px">Жаңарту</button>
</form>
</div>
</div>
</div>
@endsection
файл контроллера
<?php
namespace App\Http\Controllers;
use App\Models\Achievement;
use App\Http\Requests\StoreAchievementRequest;
use App\Http\Requests\UpdateAchievementRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AchievementController extends Controller
{
public function __construct()
{
$this->Achievement = new Achievement;
$this->middleware('auth');
}
public function index()
{
$user = auth()->user();
//echo $user->id;
// dd($user);
$data = $user->Achievements;
//dd($data);
//$data = $this->Achievement->getData();
return view ('Teacher.Achievement.list',compact('data','user'));
}
public function create()
{
//$team = Team::find (1);
//$user = auth()->user();
//if(!$user->hasTeamPermission($team, 'create'))
//{
// abort(401,'sdsasdasdsa');
// }
$user = auth()->user();
$data = $user;
$roles = DB::table('dengei')->get();
$cats = DB::table('categorie')->get();
//dd($cats);
return view('Teacher.Achievement.create',compact('data','roles','cats'));
}
public function store(StoreAchievementRequest $request)
{
//$team = Team::find (1);
//$user = auth()->user();
//if(!$user->hasTeamPermission($team, 'store'))
//{
// abort(401,'sdsasdasdsa');
// }
$input = $request->all();
$this -> validate($request,[
'user_id'=>'required',
'Dats' => 'required',
'Level' => 'required',
'turi' => 'required',
'Description' => 'required',
'sureti' => 'required',
]);
$this->Achievement->createAchievement($input);
/*return redirect()->back()->with('success', 'Жетістік сәтті қосылды');*/
return redirect()->route('Achievement.index')->with('success', 'Жетістік сәтті қосылды');
}
public function show($id)
{
$this->Achievement->deleteData($id);
return redirect()->back()->with('success', 'Жазба өшәрілді');
}
public function edit($id)
{
//$user = auth()->user();
//$data = $user;
//echo $data->id;
$data = $this->Achievement->findData($id);
$roles = DB::table('dengei')->get();
return view('Teacher.Achievement.edit',compact('data','roles'));
}
public function update(Request $request, $id)
{
$input = $request->all();
$this->Achievement->updateData($id,$input);
//return redirect()->back()->with('success', 'Жетістік сәтті қосылды');
return redirect()->route('Achievement.index')->with('success', 'Жетістік сәтті жаңартылды');
}
public function destroy(Achievement $Achievement)
{
//
}
public function getArtices (Request $request)
{
$user = User::find(1);
dump($user);
}
}
Например у записи значение поля Level - Облыстык на база
при открытии записи для редактирование по поле SELECR VALUE подставляется первое значение $roles - Аудандык
Не в сети
Страницы 1