Я пытаюсь получить параметр id_berita
, он отображается в URL, но когда я хочу показать предыдущие данные, он не может ....
Контроллер
class KontenController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth:admin');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$berita = Berita::all();
return view('backpages/berita', compact('berita'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('backpages.berita_input'); //untuk menampilkan form add
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
request()->validate([
'id_berita' => 'required',
'id_kategori' => 'required',
'username' => 'required',
'tanggal' => 'required',
'judul' => 'required',
'isi' => 'required',
]);
Berita::create($request->all());
$request->session()->flash('pesan','Berita '.$request['id_berita'].' berhasil disimpan.');
return redirect()->route('berita.index');
}
/**
* Display the specified resource.
*
* @param \App\Berita $berita
* @return \Illuminate\Http\Response
*/
public function show(Berita $berita)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Berita $berita
* @return \Illuminate\Http\Response
*/
public function edit(Berita $berita)
{
// return view('backpages.berita_edit',compact('berita'));
$berita = Berita::find($berita);
// return view('backpages.berita_edit')->with('berita',$berita);
return view('backpages.berita_edit')->with('berita', $berita);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Berita $berita
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Berita $berita)
{
request()->validate([
'username' => 'required',
'tanggal' => 'required',
'judul' => 'required',
'isi' => 'required',
]);
$berita->update($request->all());
$request->session()->flash('pesan','Berita '.$request['judul'].' berhasil
diperbarui.');
return redirect()->route('berita.index');
}
/**
* Remove the specified resource from storage.
*
* @param \App\Berita $berita
* @return \Illuminate\Http\Response
*/
public function destroy(Berita $berita)
{
//
}
}
berita_edit.blade. php для процесса обновления
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">Edit Berita</h3>
</div>
<!-- /.card-header -->
<!-- form start -->
<form action="{{route('berita.update')}}" method="POST">
{{ csrf_field() }}
{{method_field('PUT')}}
<div class="card-body">
<div class="form-group">
<label for="exampleInputPassword1">Username</label>
<input type="text" class="form-control" name="username" placeholder="Username" value="{{ $berita->username }}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Tanggal</label>
<input type="date" class="form-control" name="tanggal" placeholder="Tanggal" value="{{ $berita->tanggal }}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Judul</label>
<input type="text" class="form-control" name="judul" placeholder="Judul" value="{{ $berita->judul }}">
</div>
<div class="form-group">
<label>Isi</label>
<textarea class="form-control" rows="3" name="isi" value="{{ $berita->isi }}" placeholder="Enter ..."></textarea>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
Для отображения данных
<div class="card-body table-responsive p-0">
<table class="table table-hover text-nowrap">
<thead>
<tr>
<th>id_Berita</th>
<th>id_Kategori</th>
<th>Username</th>
<th>Tanggal</th>
<th>Judul</th>
<th>Isi</th>
<th colspan="2" style="text-align:left">Opsi</th>
</tr>
</thead>
<tbody>
@foreach($berita as $data)
<tr>
<td>{{$data -> id_berita}}</td>
<td>{{$data -> id_kategori}}</td>
<td>{{$data -> username}}</td>
<td>{{$data -> tanggal}}</td>
<td>{{$data -> judul}}</td>
<td>{{$data -> isi}}</td>
<td>
<a class="btn btn-block btn-info" href="{{ route('berita.edit', $data -> id_berita) }}"?>Edit</a>
</td>
<td>
<a class="btn btn-block btn-info" href="#"?>Hapus</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>