Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ramazan's avatar

passing data by form use post method to the table

ErrorException thrown with message "Trying to get property of non-object (View: C:\xampp\htdocs\goodluck\resources\views\layout\show.blade.php)"

0 likes
10 replies
rin4ik's avatar

show your show.blade.php file please

Ramazan's avatar

@extends('layout.index')

@section('title')

show Page one

@stop

@section('content')

       <h1>{{$card->title }}</h1>


            <ul class="list-group">
                @foreach($card->notes as $note)
                    <li>
                        <h3>
                            {{$note->body}}
                        </h3>
                    </li>
                @endforeach
            </ul>
       <t3>add new note</t3>
       <hr>


       <form method="post" action="/show/{card}/notes">
           <div class="form-group">
                <textarea name="body" title="body" class="form-control"></textarea>
            <div class="form-group ">
                <button type="submit" class="btn-default">add some text</button>
            </div>
           </div>
       </form>


   </div>
@stop
rin4ik's avatar

do you have that relationship in your Card model?

public function notes()
{
return $this->hasMany(Note::class);
}

and did you include relation in your controller

$card=Card::with('notes')->get();

Ramazan's avatar

class Card extends Model { public function notes(){

    return $this ->hasMany(Note::class);

}

}

rin4ik's avatar

show your controller method please

Please or to participate in this conversation.