Postingan lainnya
Error Missing required parameters for [Route: ] [URI: admin/user/update/{id}].
Harap dibantu ya teman teman, saya udah berusaha tapi belum dapet juga solusinya, (awam coding)
ini link error saya
https://flareapp.io/share/353VVgE7
dibawah ini web.php saya yg isi routenya
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::prefix('admin')->middleware('auth')->group(function ()
{
Route::get('user/index','UserController@index');
Route::get('user/tambah','UserController@tambah');
Route::post('user/simpan','UserController@simpan');
Route::get('user/edit/{id}','UserController@edit');
Route::put('user/update/{id}','UserController@update');
}
);
dibawah ini UserController.php saya
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index(Request $request)
{
$data['objek']=\App\User::latest()->paginate(10);
return view('user_index', $data);
}
public function tambah()
{
$data['objek']=new \App\User();
$data['action']='UserController@simpan';
$data['method']='POST';
$data['nama_tombol']='SIMPAN';
return view('user_form', $data);
}
public function simpan(Request $request)
{
$request->validate([
'name'=>'required|min:2',
'email'=>'required|email|unique:users,email',
'password'=>'same:password_confirmation'
]);
$objek=new \App\User();
$objek->name=$request->name;
$objek->email=$request->email;
$objek->password= bcrypt($request->password) ;
$objek->save();
//\App\User::create($request->except('password_confirmation'));
return back()->with('pesan','data sudah disimpan');
}
public function edit($id)
{
$data['objek']= \App\User::findOrFail($id);
$data['action']='UserController@update';
$data['method']='PUT';
$data['nama_tombol'] ='UPDATE';
return view('user_form', $data);
}
public function update(Request $request, $id)
{
$request->validate([
'name'=>'required|min:2',
'email'=>'required|email|unique:users,email' . $id,
'password'=>'same:password_confirmation'
]);
$objek= \App\User::findOrFail($id);
$objek->name=$request->name;
$objek->email=$request->email;
if ($request->password != "")
{
$objek->password = bcrypt($request->password);
}
$objek->save();
return redirect('admin/user/index')->with('pesan','data sudah di update');
}
public function hapus($id)
{
$objek= \App\User::findOrFail($id);
$objek->delete();
return back()->with('pesan','data berhasil dihapus');
}
}
0
Tanggapan
coba di vard_dump($id) yang berada pada fungsi update. itu dia belum nangkap nilai id. atau id bernilai null
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban