Mengatasi error laravel

Selamat pagi..

saya sedang membuat aplikasi tetapi ketika akan update data menampilkan eror

Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id_grup (View: C:\xamppp\htdocs\bismillahAset\resources\views\halaman\groupAsset.blade.php)

mohon bantuannya..

web.php

// CRUD groupAsset
Route::post('/simpangroupAsset', 'groupAssetController@store')->name('simpangroupAsset');
Route::get('/editgroupasset/{id}', 'groupAssetController@edit')->name('editgroupasset');
Route::post('/updategroupasset/{id}', 'groupAssetController@update')->name('updategroupasset');
Route::get('/deletegroupasset/{id}', 'groupAssetController@destroy')->name('deletegroupasset');

groupAsset.blade.php

<!--MODAL EDIT -->
<div class="modal fade" id="quoteFormEdit" tabindex="-1" role="dialog" aria-labelledby="quoteForm" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Edit Group Asset</span></h4>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
            </div>
            <div class="modal-body">
                <form action="{{ url ('updategroupasset',$groupasset->id_grup) }}" method="post">
                    {{ csrf_field() }}
                    <div class="row">
                        <div class="form-group col-4">
                            <label class="font-weight-bold text-small" for="kode_grup">Kode Group Asset<span class="text-primary ml-1">*</span></label>
                            <input class="form-control" id="kode_grup" name="kode_grup" type="text" placeholder="Kode Group Asset" required="" value="{{$groupasset->kode_grup}}" />
                            @error('kode_grup')
                            <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>
                        <div class="form-group col-8">
                            <label class="font-weight-bold text-small" for="nama_grup_aset">Nama Group Asset<span class="text-primary ml-1">*</span></label>
                            <input class="form-control" id="nama_grup_aset" name="nama_grup_aset" type="text" placeholder="Nama Group Asset" required="" value="{{$groupasset->nama_grup_aset}}" />
                            @error('nama_grup_aset')
                            <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>
                        <div class="form-group col-4">
                            <label class="font-weight-bold text-small" for="tipe_depresiasi">Tipe Depresiasi<span class="text-primary ml-1">*</span></label>
                            <div class="btn-group mb-2 col-8">
                                <div class="dropdown">
                                    <button class="btn btn-primary dropdown-toggle me-1" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" value="{{$groupasset->tipe_depresiasi}}">
                                        Pilih Tipe
                                        Depresiasi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    </button>
                                    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                        <a class="dropdown-item" href="#">Straight-Line</a>
                                        <a class="dropdown-item" href="#">Double Declining Balance</a>
                                    </div>
                                    @error('tipe_depresiasi')
                                    <small class="text-danger">{{ $message }}</small>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="form-group col-4">
                            <label class="font-weight-bold text-small" for="tahun">Tahun<span class="text-primary ml-1">*</span></label>
                            <input class="form-control" id="tahun" name="tahun" type="text" placeholder="0" required="" value="{{$groupasset->tahun}}" />
                            @error('tahun')
                            <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>
                        <div class="form-group col-4">
                            <label class="font-weight-bold text-small" for="depresiasi">Tarif Depresiasi<span class="text-primary ml-1">*</span></label>
                            <input class="form-control" id="depresiasi" name="depresiasi" type="text" placeholder="0,00" required="" disabled />
                            @error('depresiasi')
                            <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>
                        <div class="form-group col-lg-12"><br>
                            <button class="btn btn-success" style="float: right;" type="submit">
                                <i class="fa fa-save"></i>
                                Save
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

groupAssetController

<?php

namespace App\Http\Controllers;
namespace App\Http\Controllers;

use App\Models\groupAsset;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class GroupAssetController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $groupasset = groupAsset::paginate(10);
        return view('halaman.groupAsset',compact('groupasset'));


    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('halaman.groupAsset');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'id_grup' => 'required',
            'kode_grup' => 'required',
            'nama_grup_aset' => 'required',
           // 'tipe_depresiasi' => 'required',
            'tahun' => 'required',
            //'depresiasi' => 'required',
        ]);

        //dd($request->all());

        groupAsset::create([
            'kode_grup' => $request->kode_grup,
            'nama_grup_aset' => $request->nama_grup_aset,
            // 'tipe_depresiasi' => $request->tipe_depresiasi,
            'tahun' => $request->tahun,
            // 'depresiasi' => $request->depresiasi,
        ]);

        return redirect('groupAsset')->with('success', 'Data Berhasil Disimpan!');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $groupasset = groupAsset::findorfail($id);
        return view('halaman.groupAsset',compact('groupAsset'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id_grup)
    {
        $groupasset = groupAsset::findorfail($id_grup);
        $groupasset->update($request->all());
        return redirect('groupAsset')->with('success', 'Data Berhasil Diupdate!');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id_grup)
    {
        $groupasset = groupAsset::findorfail($id_grup);
        $groupasset->delete();
        return redirect('groupAsset')->with('status', 'Data Berhasil Dihapus!');
    }
}

avatar zkdlinnn
@zkdlinnn

10 Kontribusi 2 Poin

Diperbarui 1 tahun yang lalu

1 Jawaban:

<div>cek apa isi dari $groupasset kamu<br><br>Errornya menunujukkan kalau id_grup tidak bisa diakses</div><pre>$groupasset-&gt;id_grup</pre>

avatar hilmanski
@hilmanski

2686 Kontribusi 2135 Poin

Dipost 1 tahun yang lalu

Login untuk ikut Jawaban