I want get id value from eloquent laravel and passing to variable to insert process. this is my eloquent to get data from siswa table
$siswa = Siswa::where('nis', $row['nis'])->first();
but when accessing id value like $siswa->id I'm getting error enter image description here
CodePudding user response:
Use this code
if($siswa){
$id=$siswa->id;
}
CodePudding user response:
$siswa variable can be null. Look at its contents with the dd($siswa)
command.
To escape the error you can use it like this:
if($siswa)
{
// $siswa not null.
}
CodePudding user response:
=>first you can $id pass on your public function like
public function show($id)
{
$siswa = Siswa::where('id', $id)->first();
}
=>you can pass your id on your route